Constructors can have arguments
// : c04:SimpleConstructor2.java
// Constructors can have arguments.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
class Rock2 {
Rock2(int i) {
System.out.println("Creating Rock number " + i);
}
}
public class SimpleConstructor2 {
public static void main(String[] args) {
for (int i = 0; i < 10; i++)
new Rock2(i);
}
} ///:~
Related examples in the same category