If you want to “construct” an object each time you create an object with PRE-DEFINED or DEFAULT VALUES, you can create a specialized method called a no argument constructor that is called when the object is first created.
NOTE: You could create an object without a constructor but it would have NO STATES. Then, you could add values to set the INITIAL STATES afterward. However, a no argument constructor allows you to create an object and INITIALIZE it with DEFAULT VALUES at the SAME time.
REPLACE LATER WITH OWN SCREENSHOTS
Before:
After:
public class MyCustomBox { // DEFINING instance variables (properties) public String height; public String width; // regular constructor method for 2D object public MyCustomBox() {
// ASSSIGNING instance variables (properties) height = 100; width = 100; } // Other methods here... }
Now, create an object (a 2D object) from the class:
MyCustomBox my2DBox = new MyCustomBox();
Both the height and width properties would be 100:
height:100
width: 100
NOTES: