1. How is an object \"instantiated\" in a cient program? Provide an example. Wha
ID: 3748744 • Letter: 1
Question
1. How is an object "instantiated" in a cient program? Provide an example. What two things make a constructor different from other methods in a class? 2. Explain how "information hiding" is accomplished with attributes and behaviors of a class When would a method be declared as private instead of public? Give an example. What does the term "encapsulation" mean in terms of defining objects of a class? How does that make it possible to write code time-efficiently and cost-effectively? 3. 4. When is the word "static" used in defining variables or methods? How does this change the way that a client program refers to it? 5. When is the keyword "this" used? When is the keyword "null" used?Explanation / Answer
Answer 1: object is instantiated using the key word new
example : new Student();
method has the return type constructor does not have return type
we can call method any number of times using object, but constructor will call only once per object
Answer 2:
information hiding can be done by making the variables as private
if any methods has internal use and sensitive functionality is there than make that method as private
Answer 3:
encapuslation is the process of combining the methods and variables into single container called class,
as all the related methods and attributes will be available in same location it will be easy for developers to write the code
Answer 4:
if any class has common property for all the objects like college name,dog legs etc these are common for every object so we will make it as static, for methods if we want access without creating any object than we will make tham static
we can refer static variables and methods using class name
Answer 5:
this is used to refer the current object, when you want to return current object, or when you want use current object values this is used
null is value which is used give it to the reference variables
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.