• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Constructor of parent abstrat class not getting executed.  RSS feed

 
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
 
Bartender
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.
 
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...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!