forked from coder2hacker/Explore-open-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJava Constructor
1 lines (1 loc) · 965 Bytes
/
Java Constructor
1
As a great follow-up to Chris Hermansen's overview of the Java object, I recommend reading What is a Java constructor? The constructor is an important concept to understand when working within the realms of OOP and Java, and Seth Kenlon introduces it in this easy-to-understand guide. The constructor in Java (and most OOP languages) is where you instantiate or create an instance of an object you have defined. In many languages, an instance is created with the new keyword and the object you want to create. For example, Dog fluffy = new Dog(); will create a new instance of Dog. Constructors can also set properties within the object you are instantiating; therefore, if you have an implementation for a constructor to set your object's size, height, and type, you can set those all from the constructor. By default, Java allows objects to be instantiated with the new keyword without having an explicit constructor defined and creates them at compilation time.