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

Constructor of parent abstrat class not getting executed.

 
Abhishek Khanna
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abhishek Khanna
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It worked after making the call to super.

Thanks Wouter.
 
Hardik Trivedi
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic