Special Offer - Enroll Now and Get 2 Course at ₹25000/- Only Explore Now!

All Courses
Constructors in Java

Constructors in Java

May 1st, 2019

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;
}
}