Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

constructor lovers..

 
chintan ramavat
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello ranchers

can anyone ll me why we need SUPER CLASS constructors and does it reflect to the subclasses, if so then whats the benefit of it. IF there's an abstract class in IS-A hierarchy then what's the outcome of having constructed SUPER CLASS.


Thank you ranchers
good night. would like to think about it in dreams hehe

Chintan Ramavat
 
Mamatha Preetham
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chintan,

Hope you had nice dreams!!
The constructor explicitly initializes the instance variables defined in the class, but it relies on the superclass constructor. And, by this time, you might be knowing that Object class is the super class for all the class. The instance variables are not initialized until after your super class constructor runs.

To invoke the superclass constructor, the constructor calls super(), which is a java keyword.

FYI The arguments pased to super() must match the parameters of the superclass constructor.

If you want constructors in your sub class , you will have to define a new one, else the compiler will provide a default one with no parameters.
Hope I made some sense for your question.....

mamatha
SCJP(1.4)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic