June 2018
Beginner
722 pages
18h 47m
English
By now, we have seen examples of the new operator being used many times. It instantiates (creates an object of) a class by allocating memory for the new object and returning a reference to that memory. This reference is then typically assigned to a variable of the same type as the class used to create the object or the type of its parent, although we have also seen a case when the reference was never assigned. In Chapter 6, Interfaces, Classes, and Object Construction, for example, we used this code to demonstrate how the constructors are called:
new Child();new Child("The Blows");
But such cases are very rare and most of the time we need a reference to the newly created object in order to invoke its methods: ...
Read now
Unlock full access