O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The preceding application produces the following output:

As you can see, an engine object was created by invoking the default constructor of the Engine class without parameters and with the Java keyword new that allocated memory for the newly created object on the heap.

The second object, namely vehicle, was created with the explicitly defined constructor of the Vehicle class with two parameters. The second parameter of the constructor is an engine object that carries the horsePower property with the value set as 246, using the setHorsePower() method.

It also contains the getSpeedMph() method that can be called by any other ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required