aspose file tools*
The moose likes Beginning Java and the fly likes Abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract class" Watch "Abstract class" New topic
Author

Abstract class

sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1031
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: 36453
    
  15
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: 597

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: 597

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Abstract class
 
Similar Threads
ABSTRACT
A question about container!
HttpServlet class
A mock question
usage of a class