
Constructors in Java
Constructors in Java
Constructors are special methods for a class , we have two types of constructors:
- Default Constructor
- Parameterized Constructor
Example:
Class Employee { Employee() { System.out.println("Default Constructor is running"); name=null; doj=null; salary=0; check=0; } Employee (String name,String d,long l) { sample=sample+1; check=check+1; this.name=name; this.doj=d; this.salary=l; } } |