Hi,
I am not convinced with the answers in chapter 2 [
SCJP 1.5,K&B] Self
Test questions 7 and 9.
Question 7:
So in the above question we need to insert code to make it compile.
My solution is :
Just add no-arg AgedP().
public AgedP() {
}
K&B solution is
a) Add no-arg AgedP().
b) And also explicitly invoke the default AgedP() in Kinder(int x) using
super().
Since the compiler will implicitly put super() in Kinder(int ) there is no need for us to insert super() in Kinder(int )
Please advice?
Question 9:
Given below code, Choose correct option
Answer is : Woop is-a Zing and Woop has-a Hmpf
Here first part of the answer Woop is-a Zing is correct and straight-forward because Woop extends Zing.
Now second part Woop has-a Hmpf will be correct if Woop inherted the Hmpf variable 'h'.
a) Does inheritance apply to instance variables also?
b) Isn't instance methods are the only thing that are inherited by
subtype?
I verified the second part by writng the below method in Woop class
and to my surprise i found it working which verifies that the answer
is correct.
So does child class inherits non-private instance variables along with non-private methods from parent class?
Please advice.
Thanks
Deepak