<<< Basic Components of a Class | Index | Object creation and method calls >>> |
Defining a class does not create any objects
Java code has to be written to create objects from a user-defined class. For example,
Locomotive loco = new Locomotive(); BoxCar box = new BoxCar( 50 ); // a box car that weighs 50 ton Train freight = new Train( loco, box ); // create a train with 1 loco and 1 boxcar
<<< Basic Components of a Class | Index | Object creation and method calls >>> |