I thought the new Derived(2) will invoke the constructor with long arg which will invoke the super constructor(in this case Base) with int arg and would display "the base constructor with int arg" but it gives a compile time error as above
Can someone explain how ?
Originally posted by Henry Wong:
In the case, the problem is with the other Derived constructor (that takes no parameters). It doesn't specify which Base constructor to use, which means that it will use the no-arg base constructor, which doesn't exist.
Henry
Kiran
Originally posted by Kiran Gavate:
Hi Madhavi,
When you replace the Derived() {} by Derived (String s) { } constructor, it still compiles because you are not calling the default (no-args) constructor of the derived class in your code.
Originally posted by Kiran Gavate:
Hi Madhavi,
When you replace the Derived() {} by Derived (String s) { } constructor, it still compiles because you are not calling the default (no-args) constructor of the derived class in your code.
now suppose i replace the Derived() {} by Derived (String s) { } constructor.the code compile fine ... though Base constructor with String arg does not exist...
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Originally posted by Barry Gaunt:
As Henry predicted, the code does not compile unless the no-args constructor Base() is provided. I just tried it to prove it.
Kiran