4 Default Constructor is a constructor that takes no arguments.
4 Default Constructor is compulsory when there are parameterized constructors and one or more objects have no arguments in the program.
4 Default constructor is always advised to avoid garbage values for data members because this is used for providing default values for data-members.
4 Generally, this is used for assigning default initialization of values for the properties of the object.
Example:
class point
{
private int x,y;
point() // default Constructor
{
x=y=0;
}
point(int xx, int yy)
{
x=xx;
y=yy;
}
}
class Test
{
public static void main(String as[])
{
point p1=new point(3,4);
point p2= new point();
}
}
0 comments:
Post a Comment