Java Reference
In-Depth Information
You should call the file that contains this program VehicleDemo.java because the main(
) method is in the class called VehicleDemo , not the class called Vehicle . When you com-
pile this program, you will find that two .class files have been created, one for Vehicle
and one for VehicleDemo . The Java compiler automatically puts each class into its own
.class file. It is not necessary for both the Vehicle and the VehicleDemo class to be in
the same source file. You could put each class in its own file, called Vehicle.java and Ve-
hicleDemo.java , respectively.
To run this program, you must execute VehicleDemo.class . The following output is dis-
played:
Before moving on, let's review a fundamental principle: each object has its own copies
of the instance variables defined by its class. Thus, the contents of the variables in one ob-
Search WWH ::




Custom Search