• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

master exam question

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

the answer of this question is Compilation fails... and the explanation says "Uber's constructor's call to this is looking for a no- argument constructor that doesn't exist"... i have not understood this... i have got confused please explain me this...
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Compilation fails cause Uber doesn't declare the no-arg constructor
Uber(){}.
A call to this() is a call to the no-arg constructor.

Remember the follwoing rules:

If you don't type a constructor into your class code, a default constructor will be automatically generated by the compiler(the no-arg constructor).

If you want a no-arg constructor and you've typed any other constructor into your class code, the compiler won't provide the no-arg constructor.
 
sweety singh
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply... i wanted to ask one more thing...
in the following code... when the minor class's constructor calls its base class constructor with arguments.. ie super(y) at line 1.. is it that 'y +=3' also executes or before it is executed the base class constructor is called.??? then when is it executed.... same is the case with this()..

[ June 08, 2008: Message edited by: sweety singh ]
 
sweety singh
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
anyone please answer this question...
 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be patient Sweety.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
y+=3 is executed after the base class constructor is called. If you comment out the line that says this(); and put run you will see what the result of y is and this should make it easier to understand what is happening.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just another minor addition to remember for the exam is that if the super class has any Static init blocks or any instance init blocks then those would be called before the y += 3 statement.
 
There's a city wid manhunt for this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic