Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract class constructor

 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.....
 
Avishkar Nikale
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks now i understand that.........
 
Avishkar Nikale
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic