The previous couple of days I have been going through Java programming
seeking to understand well the Object concept of an Object Oriented Programming
(OOP) language.
Code: Select all
Vehicle car;
car = new Vehicle ();
create an object. The second, which is an assignment statement, creates
a new object which is an instance of class Vehicle, and a reference of that
object is stored in variable car.
In Java no variable holds an object. A variable holds reference to an object.
Quoting David J. Eck of Hobart and William Smith Colleges, Geneva, New York:
Guys; I can’t still help myself with this object concept. The object is so theoretical.You should think of objects as floating around independently in the computer’s memory. In
fact, there is a special portion of memory called the heap where objects live. Instead of holding
an object itself, a variable holds the information necessary to find the object in memory. This
information is called a reference or pointer to the object. In effect, a reference to an object
is the address of the memory location where the object is stored. When you use a variable of
class type, the computer uses the reference in the variable to find the actual object.
In a program, objects are created using an operator called new, which creates an object
and returns a reference to that object.
How do other OOP languages like C++ define an object? Bring it on guys!