• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Constructor doubt inside heritance

 
Ranch Hand
Posts: 49
Eclipse IDE Spring Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello! .

A example in code:



Compiler says I need default constructor in parent class cause of the implicit call to super in the child's constructor. I thought , this would apply only when I am using the default constructor in the child but not with any defined constructor you define , when not defining the default one.
So, it doesn't matter what constructor I define in the child class because it always will have implicitly a call to super() ?

I simply don't understand the implicit call to super() in child constructor (being a non default one).

Thanks for the answers

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Child's constructor always will call to super(); in the first statement if you don't call explicity another Parent's constructor. If you call explicity "super(b)" in the first statement, it would be ok.

 
David Samer
Ranch Hand
Posts: 49
Eclipse IDE Spring Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it because no matter what kind of constructor class has, it will always have a call to super() implicitly?
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, always is called super() implicity if you do not add a called to other constructor, for example, this(...). So, if you do not have a default constructor in the super class (your case), you need add it explicity.

You code will compile without the call "super(b)" if you take off all the constructor of Parent:



or if you add a defaul constructor to your example:




Sorry for me english.
 
David Samer
Ranch Hand
Posts: 49
Eclipse IDE Spring Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thank you Alam
 
grapes are vegan food pellets. Eat this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic