| Author |
Abstract class
|
sameera liyanage
Ranch Hand
Joined: Nov 25, 2008
Posts: 690
|
|
Does abstract class has constructor?
-when we make the object of a concrete class what happen to the abstract class?
|
 |
Eric Daly
Ranch Hand
Joined: Jul 11, 2006
Posts: 143
|
|
No, an abstract class does not have a constructor because it is never instantiated (made into an object). There is nothing to "construct."
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
|
Studying for SCJP 6
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
|
I am afraid you are mistaken. Abstract classes can have constructors. And when you instantiate the subclass, part of that subclass object is "made from" the abstract superclass.
|
 |
Eric Daly
Ranch Hand
Joined: Jul 11, 2006
Posts: 143
|
|
|
Darn! Sorry for giving false information... It's been too long since I've studied Java in depth, I really need to get back into it. Thanks for the correction! I will try to remember it this time!
|
 |
Ryan Beckett
Ranch Hand
Joined: Feb 22, 2009
Posts: 192
|
|
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
Ranch Hand
Joined: Apr 15, 2008
Posts: 131
|
|
Just to add one more thing to the question,
Can abstract class have parameterized constructor?
|
<a href="http://technologiquepanorama.wordpress.com" target="_blank" rel="nofollow">My Techie Blog</a><br /><a href="http://www.java-questions.com" target="_blank" rel="nofollow">Java Questions</a>
|
 |
Saifuddin Merchant
Ranch Hand
Joined: Feb 08, 2009
Posts: 576
|
|
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!!
|
Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
|
 |
Harshit Rastogi
Ranch Hand
Joined: Apr 15, 2008
Posts: 131
|
|
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...
|
 |
Saifuddin Merchant
Ranch Hand
Joined: Feb 08, 2009
Posts: 576
|
|
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
|
 |
 |
|
|
subject: Abstract class
|
|
|