• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Constructors!!!!Please help !!!!!

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could someone please help me out with this, its a modification of a question I came across in Jxam:

This code as is, compiles correctly, but when the super(k) call is removed, it gives a compile time error : No constructor in matching Parent() in class Parent
Child(int k{

I know that child class construtors make an implicit call to the superclass's 'no-args' constructor and thats why the error.
If you remove the child class altogether, the code compiles correctly. My query is that in the main method the code is Parent p = new Parent(6).....so why are the child-class constructors-calls, in the picture at all. Should'nt the output just be .....This is the Parent Constructor 6....
Help!!!
Rebecca
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The compiler checks the syntax of the entire code. So, even though the TestConstructor class does not call the Child class's constructor, the compiler still checks the correctness of the Child class. Thus, the compiler detects that the Child class's constructor is flawed.
 
Rebecca Mathew
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Yang, after reading your answer I feel silly as to not know that myself
reply
    Bookmark Topic Watch Topic
  • New Topic