class cons
{
int l;
int b;
cons() // default constructor
{
l=1;
b=2;
}
cons(int tl) // function name is same as class name
{
l=tl;
b=4;
}
cons(int tl,int tb) // class name same as function name with different parameter
{
l=tl;
b=tb;
}
void display()
{
System.out.println("\n");
System.out.println("Length of the rectangle = "+l);
System.out.println("Breadth of the rectangle = "+b);
}
public static void main(String arg[])
{
cons r1=new cons();
r1.display();
cons r2=new cons(6);
r2.display();
cons r3=new cons(10,20);
r3.display();
}
}In this Program easy to understand Java Constructor concept
