Java Class

Review of class 2

Creating Objects

Java objects are created by "instantiating" a Java class. This creates a copy of the class data items which is linked to the class Java code. In Java, you use the "new" keyword to do this object creation:

bozo = new Clown();

In NetRexx, the "new" keyword is not used:

bozo = Clown()

The statement which creates the Java object causes the JVM to create a copy of the class variables which are not shared by the class (ie not static) and then to call the class' constructor method to do any needed initialization instructions. The constructor is a method with the same name as the class. Multiple constructors with different parameters are OK. The one that matches the creation call is picked at compile time. Note that "abstract" classes such as the Math class are perfectly reasonable - no objects are created for them, but the subroutines are still callable.