Tweet
public class consdemo
{
int a;
consdemo() // default constructor
{
a=10;
}
consdemo(int x) // parametrized constructor
{
a=x;
}
consdemo(consdemo obj) // copy constructor
{
a=obj.a;
}
void disp()
{
System.out.print(" " + a);
}
public static void main(String args[])
{
consdemo obj1=new consdemo();
obj1.disp();
consdemo obj2=new consdemo(9);
obj2.disp();
consdemo obj3=new consdemo(obj1);
obj3.disp();
}
}
Output : 10 9 10
How to use different types of constructors in Java ?
Posted by
LAHAUL SETH
~
How to use different types of constructors in Java ?
2012-03-08T13:50:00+05:30
LAHAUL SETH
Java
|
Comments
How to use different types of constructors in Java ?
2012-03-08T13:50:00+05:30
LAHAUL SETH
Java
|