All Courses
Constructors in Java

Constructors in Java

May 1st, 2019 Java

Constructors in Java

Constructors are special methods for a class , we have two types of constructors:

  1. Default Constructor
  2. 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;
}
}
Social Share:

0 responses on "Constructors in Java"

Leave a Message

Your email address will not be published. Required fields are marked *