Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. How is an object \"instantiated\" in a cient program? Provide an example. Wha

ID: 3748982 • 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)
Considering a Vehicle class with attibutes like
wheels, seats etc with a constructur and getter and
setter methods.

Object will be instantiated for the class via Command

Vehicle v = new Vehicle();
where v will be oject name


Constructors are different other methods because
a) constructor name is same as class name
b) constructor does not have a return tupe

2)
Information hiding is done by making members of class private.

Inorder to make a method Inaccessible, methods are made private instead of public

3)
Encapsulation is an Object oriented programming concept by which object and methods are wrapped together.

Since information hiding is done by making attributes private
and they cannot be accessed directly. Only getters and setters
can access them which secures the application and can be extended easily making it time and cost effective.


4)
When only a single copy of variable is required to be shared by objects at class level, then members are deeclared static.


When a member is declared static, it can be accessed before any objects of its class are created, and without reference to any object being a single copy for all objects.


5)
This keywork refers to the current object

Null value indicates a unset/empty reference.