1. How is an object \"instantiated\" in a cient program? Provide an example. Wha
ID: 3748739 • 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
1. Instantiation is the process of creating objects from class in object oriented languages.
example: public var myFirstObject:science=new science();
myFristObject.x=300;
myFirstobject.visible=true;
Here x,visible are objects created by a single class instatiation
Constructors create and initialize objects that doesnt exist where as the methods perform action on which already exist and construtors should be called with same name as class name where void is not allowed and methods can take any name even void.
2.An information hiding is all about hiding the information related to an object stored with the object itself which can be hidden from the outisde world and can only be manipulated by the object that is state,attribute and behaviour of a class.
when a particular method is declared private it can be hidden from the outside world and can only be manipulated within the method so the best example is data encapulation
3.Encapsulation is also calledas data hiding its all about hiding the implementation details from the users. If the class is defined as private then the objects of the class can only be accessed within the same class.
Code efficiently is to reduce the resource consumption and completion time whereas the code effectively is to get the correct output with the given inputs
4.when a word static is used with defining a variable or method then it belongs to the whole class but not to one of its certain objects.it should be used only within the class scope.it is initialised at the start of the execution
A static method or variable can be accessed directly by the class name and doent need any object
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.