File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Abstract class constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Abstract class constructor" Watch "Abstract class constructor" New topic

Abstract class constructor

Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

As we all know that constructor have to deal with the object instantiation.....

then how can a Astract class have a constuctor....

Just look into a PageNo-131 of kathy book......
first line of Topic constructor basics says......
"Every class, including abstract classes, MUST have a constructor. Burn that into your
brain. But just because a class must have one, doesn't mean the programmer has to
type it."

but how please clarify.....

SCJP6.0,My blog Ranchers from Delhi
Avishkar Nikale
Ranch Hand

Joined: Aug 06, 2010
Posts: 173
Hi Shanky,

Please remember that the constructor is a access point where in you can define the initial state
of your newly created instance.

Since the state of the instance is also governed by what it inherits, it is necessary to invoke that parent class constructor.

Remember you can never do

But this constructor will be called when any subclass is created during the object creation.

All the parts are nicely explained further in the book. Have a go at the later part & come back if you have more queries.

Remember - the asbtract class constructor helps in creating the subclass instance & initialize the inherited part of the subclass instance
This does not mean that a abstract class instance is being created when the constructor is invoked through subclass instance
creation chain.

Avishkar Nikale
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Thanks now i understand that.........
Avishkar Nikale
Ranch Hand

Joined: Aug 06, 2010
Posts: 173
You are welcome Shanky,

Please do not hesitate to ask questions. Questions like these keep on re-inforcing your fundamentals.

Also you can navigate & search the forum if these type of questions have been asked previously.

This forum is an excellent sand-box where we can bruise ourselves as much as we want
before we head out for the test.

It is sorta covered in the JavaRanch Style Guide.
subject: Abstract class constructor
Similar Threads
An abstract class has a constructor?
abstract constructor question in rules roundup game
abstract class
Class Normalization using Abstract Classes