1. How is an object \"instantiated\" in a cient program? Provide an example. Wha
ID: 3748980 • 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. 3. 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? 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
1) object is instantiated in a client using new keyword and calling the constructor of the class. Example: ---------- // This is the class. Let's create an object of this class class SampleClass { } // Object of above class instantiated using new keyword SampleClass object = new SampleClass(); Two things make a constructor different from other methods 1) Constructor method does not have a return type(not even a void) 2) Constructor is called when an object is instantiated. where as other methods are called with the object created using constructor.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.