Monday, November 5, 2012

default constructor

        The default constructor is provided by the compiler only when a class does not define ANY constructor explicitly. For example,
public class A{
  public A()  //This constructor is automatically inserted by the compiler because there is no other constructor defined by the programmer explicitly.{
    super();  //Note that it calls the super class' default no-args constructor.
  }
}
public class A{
  //Compiler will not generate any constructor because the programmer has defined a constructor.
  public A(int i){
     //do something
  }
}

No comments:

Post a Comment