• 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

 
Ranch Hand
Posts: 52
Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

problem : It's asking about Parent() constructor, I am not getting where is the problem because we are not calling child consttructor.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pramod Kumar Pandey wrote:we are not creating child consttructor.


Yes you are - on lines 12 - 14.
The problem is that the compiler automatically adds a call to a no-arg parent class constructor in any constructor that doesn't explicitly call a parent constructor or an overloaded constructor. But your parent class doesn't have a no-arg constructor, so you get an error.
 
Pramod Kumar Pandey
Ranch Hand
Posts: 52
Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joanne Neal wrote:

Pramod Kumar Pandey wrote:we are not creating child consttructor.


Yes you are - on lines 12 - 14.
The problem is that the compiler automatically adds a call to a no-arg parent class constructor in any constructor that doesn't explicitly call a parent constructor or an overloaded constructor. But your parent class doesn't have a no-arg constructor, so you get an error.



Sir but when we are not creating the child object then how it will call the Child constructor ?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pramod Kumar Pandey wrote:Sir but when we are not creating the child object then how it will call the Child constructor ?


You may not be creating a Child instance in this particular piece of code but there may be other code in other files that does create a Child instance.
After all, what's the point of defining the Child class if you're never going to create an instance of it (or a subclass of it) ?
 
Pramod Kumar Pandey
Ranch Hand
Posts: 52
Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joanne Neal wrote:

Pramod Kumar Pandey wrote:Sir but when we are not creating the child object then how it will call the Child constructor ?


You may not be creating a Child instance in this particular piece of code but there may be other code in other files that does create a Child instance.
After all, what's the point of defining the Child class if you're never going to create an instance of it (or a subclass of it) ?




Thank you SIR !
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic