Wednesday, September 28, 2016

Java- Constructors

This program implements constructors in Java( parametric and non-parametric). Comment below. Have fun!!

class cons
{
int x;
cons()
{
this(1);
System.out.println("1");

}
cons(int s)
{
this('d');
System.out.println("2");

}
cons(char c)
{
this(5.6);
System.out.println("3");

}
cons(double f)
{
this(true);
System.out.println("4");

}
cons(boolean b)
{
System.out.println("5");
}
public static void main(String args[])
{
cons c1=new cons();
}
}

No comments:

Post a Comment