2nd Approach – Using the “Constructor”
Constructor is a special type of method that is present in all classes, even if you don’t explicitly define it in the class itself.
Constructors are used for creating an instance of the object…. this basically means that whenever you declare a new instance of a class, e.g.:
Employee Dave = new Employee()
Then the constructor get’s executed, and in the above case, the only thing it does is set a side a memory container, waiting to be filled in. You can identify a constructor in a class by the fact that the constructor’s name must be the same as the class’s name itself. Hence in the case of the the “Employee” class, we didn’t explicitly declare the Employee constructor,