The abstract class just provides default methods and variables for any subclass to inherit. Nothing happens to the abstract class when a subclass is instantiated, you just automatically have all the methods* and variables* when you extend the abstract class. It also can be used to require a subclass to override (or re-define) certain methods.
*depending on their access modifiers like private or public
When a new BasketBall object is created the JVM calls its constructor, but doesn't complete. Before it does BasketBall's super type constructor is called and if that object has a super type then its constructor is called before that completes, otherwise BasketBall's super type constructor completes and then BasketBall's constructor completes. All objects in java are created this way.
Harshit Rastogi wrote:Just to add one more thing to the question,
Can abstract class have parameterized constructor?
Yep they can. Look at Campbell answer for an explanation. You could easily try it out by creating a abstract class with a parameterized constructor.
Only restriction on the abstract class is that you cannot create an instance of it. Other than that all the normal rules apply!!
Harshit Rastogi wrote:
Sam Mercs wrote:
Only restriction on the abstract class is that you can create an instance of it. Other than that all the normal rules apply!!
It guess its cannot, typing mistake...
Yep a typo ... You cannot instantiate an abstract class - of course... updated .. Thanks for pointing out