hi all,
K&B chap 2 page 136 ques 6:
Given the following,
which statement is true?
A. The code compiles and runs, with output this 420 parent 420.
B. If line 8 is removed, the code will compile and run.
C. If line 10 is removed, the code will compile and run.
D. Both lines 8 and 10 must be removed for the code to compile.
E. An exception is thrown at runtime.
well undoubtedly the answer is c as a subclass outside the pacakge of the superclass can access the protected member only by inheritance i.e. it can only access them by object reference of type the sub class.
the explanation given says:
now if we go according to its explanation that
doStuff() can be accessed only by instances of the ChildUtil class
p should have accessed the protected member as its an instance of the class ChildClass.
in my opnion, the reference type used for such an acces should be of type subclass
or its further subclasses. plz verify my thought, i'll be deeply obliged.
thanx
amit
[edited because unindented code is too painful to read - Jim]
[ April 28, 2005: Message edited by: Jim Yingst ]