aspose file tools*
The moose likes Java in General and the fly likes Super class constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Super class constructors" Watch "Super class constructors" New topic
Author

Super class constructors

Sudhanshu Mishra
Ranch Hand

Joined: May 28, 2011
Posts: 207

Hi all,
why do we have to call the super class constructors in order to use the instance variables and methods of sub class.Even if we want to use the instance variables inside the constructor of the sub class,we cannot do so unless we have the constructors of all the super classes run already.
Why is so?
Why is it necessary for the sub class to run the constructors of super classes to use its own instance variables inside its own constructor?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36514
    
  16
Because a sub-class-object IS A super-class-object. that is the basis of inheritance.A car which is a green Ford also IS-A vehicle which is a green Ford. So when you create your object as a green Ford car, you have to create it as a green Ford vehicle first.
Sudhanshu Mishra
Ranch Hand

Joined: May 28, 2011
Posts: 207

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Super class constructors
 
Similar Threads
NOTES FROM VELMURUGAN'S SITES:
constructors
about "this"
help: error: cannot find symbol
Class initialization order...