OnJava8-Examples/housekeeping/SimpleConstructor.java
2020-10-07 13:35:40 -06:00

22 lines
528 B
Java

// housekeeping/SimpleConstructor.java
// (c)2020 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Demonstration of a simple constructor
class Rock {
Rock() { // This is the constructor
System.out.print("Rock ");
}
}
public class SimpleConstructor {
public static void main(String[] args) {
for(int i = 0; i < 10; i++)
new Rock();
}
}
/* Output:
Rock Rock Rock Rock Rock Rock Rock Rock Rock Rock
*/