The Role of a Constructor
Understand the role of a constructor in a Java program.
We have already covered a lot of information about constructors. By now, you must be familiar with their declaration and implementation. In this section, we’ll highlight the key points to wrap up our discussion on constructors.
🔑 Key points
🗝️ Key point 1: property of an object
An object’s state refers to its attributes and their values at a given time and is defined by instance variables belonging to the object. This creates a “has-a” relationship between the object and its instance variables.
Remember: when we create the Employee
class, every object of the Employee
class creates a ‘has-a’ relationship with its variables. Below is a demonstration to get a better idea.
Get hands-on with 1400+ tech skills courses.