How Objects Are Created
In the preceding programs, the following line was used to declare an object of type Vehicle:
This declaration performs two functions. First, it declares a variable called minivan of the class type Vehicle. This variable does not define an object. Instead, it is simply a variable that can refer to an object. Second, the declaration creates a physical copy of the object and assigns to minivan a reference to that object. This is done by using the new operator.
The new operator dynamically allocates (that is, allocates at run time) memory for an object and returns a reference to it. This reference is, more or less, the address ...
Get Java, A Beginner's Guide, 5th Edition, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.