Does a default constructor call the baseclass constructor?
satya - 11/3/2013 7:31:54 AM
Does a default constructor call the baseclass constructor?
Does a default constructor call the baseclass constructor?
Search for: Does a default constructor call the baseclass constructor?
satya - 11/3/2013 7:34:01 AM
In Java Does a default constructor call the baseclass constructor?
In Java Does a default constructor call the baseclass constructor?
Search for: In Java Does a default constructor call the baseclass constructor?
satya - 11/3/2013 7:38:44 AM
I guess a few rules
- A default constructor is provided if there are no other constructors
- if there are constructors then there is no default constructor
- Every constructor will call the supers default constructor if there is no explicit call to a super constructor
satya - 11/3/2013 7:41:20 AM
So there is no need to do this
SomeClass
{
public SomeClass(someargs)
{
super(); //this is implied
//do something with someargs
}
public SomeClass()
{
super(); //this is automatic, no need to do this
}
}
satya - 11/3/2013 7:44:44 AM
An interesting implication which the compiler will tell you anyways...
Because the super class default constructor is automatically added, if the base class defines a non default constructor and does not define a default constructor then it will be an error.