• 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

Implicit Constructor calling

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Suppose the following code
class base extends Object{
base(int x){ }
}
class child extends base{
child(String s){}
}
This would generate compile error? Why? What rules govern implicit constructor calling?
Also, What if I remove te "extends Object" from the base class signature?
Thanks alot!
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whenever you do not call a super class constructor explicitly super() is added by the compile so your secon class is actually:
class child extends base{
child(String s){}
super(); //ADDED BY THE COMPILER
}
But as you can see there is no no-arg cons. in base class so it will fail.
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See section 8.6 of the JLS for details regarding constructors, including the creation of default constructors (8.6.7)
 
reply
    Bookmark Topic Watch Topic
  • New Topic