No Constructor
Learning Outcomes
If you provide no constructor then Java provides a default one for you with no args. You can create instances of “Rock” even though it has not explicit constructor.
- Create a class called Rock.java
| Rock.java | |
|---|---|
1 2 3 4 5 | |
- Add the class SimpleConstructor.java and run it.
| SimpleConstructor.java | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 | |
Creating instance 1 of Rock
Creating instance 2 of Rock
Creating instance 3 of Rock
Creating instance 4 of Rock
Creating instance 5 of Rock