hi all i know that every class we created has a default constructor .what about the case of abstract class.is abstract class also contains one.if so when it will get invoked because we can't instantiate that
Anto Telvin Mathew<br />Many of the life failures are people who did not realize how close they were to success when they give up. EDISON
Originally posted by Anto telvin Mathew: i know that every class we created has a default constructor .
No it doesn't. Just look at java.lang.Integer. A default constructor is only added by the compiler if there are no other constructors in a class.
what about the case of abstract class.is abstract class also contains one.if so when it will get invoked because we can't instantiate that
Every constructor will call either another constructor in the same class (using this(...)) or a constructor in its parent class (using super(...)). If you as a programmer define neither, the compiler adds "super();" as the first line of your constructor.
Concrete classes that extend an abstract class are no exception. Therefore, the abstract class must have at least one constructor. If it wouldn't have the concrete classes couldn't call it and those classes wouldn't compile.
You can simulate the latter by creating a class with only private constructors. These are unavailable for all other classes including sub classes. Trying to create such a sub class will fail.