Instantiation


Instantiation is the process of creating Java class objects. This process invokes a constructor method for the given class. Figure 26.13 shows the code for a slightly modified Vehicle class. This class accepts a name as a parameter and loads a variable with that name.

image from book
Figure 26.13: Java instantiation.

The application shown in Figure 26.14 illustrates the process of creating instances of the Vehicle class. The application creates three instances of the Vehicle class, and then prints data from each instance.

image from book
Figure 26.14: Java instantiation.

The following command invokes the Buycar application:

      JAVA Buycar 

The application creates three instances of the vehicle class and then prints an instance variable from each. The output is as follows:

      Car 1 Color = Silver      Car 2 Year = 2005      Car 3 Model = Mustang 



IBM i5/iSeries Primer(c) Concepts and Techniques for Programmers, Administrators, and Sys[... ]ators
IBM i5/iSeries Primer(c) Concepts and Techniques for Programmers, Administrators, and Sys[... ]ators
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 245

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net