aspose file tools*
The moose likes Beginning Java and the fly likes Constructor of parent abstrat class not getting executed. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Constructor of parent abstrat class not getting executed." Watch "Constructor of parent abstrat class not getting executed." New topic
Author

Constructor of parent abstrat class not getting executed.

Abhishek Khanna
Greenhorn

Joined: Jan 19, 2010
Posts: 9


Hi All,

Need your help.
Please take a look at the above code.
I am expecting an output like this

Apple Orange
Fruit Orange


But I am getting the following output

Apple Orange



Could you please tell me why the code in the constructor of Fruit class not getting executed.

Thanks in advance,
Abhishek


Abhishek
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Because in the Apple constructor you don't call super(name) so the default constructor will be called.
And that does exist and doesn't output anything.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Abhishek Khanna
Greenhorn

Joined: Jan 19, 2010
Posts: 9
It worked after making the call to super.

Thanks Wouter.
Hardik Trivedi
Ranch Hand

Joined: Jan 30, 2010
Posts: 252
hey don't you think by writing super(fruit_name);

out put will be...

Fruit Orange
Apple Orange

not

Apple Orange
Fruit Orange

becauz super class will be executed first...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Constructor of parent abstrat class not getting executed.