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.
Answer given: C I didn't understand the fact that p in line 10 cannot invoke its doStuff() method.
[ August 07, 2005: Message edited by: Barry Gaunt ] [ August 07, 2005: Message edited by: Adil El mouden ]
SCWCD 1.4(Loading...), SCJP 1.4(98%), Bachelor of Engineering (computer science)
The subclasses outside the package can't use a superclass reference to access a protected member. For a subclass outside the package, the protected member can be accessed only thr' inheritance.
The ParentUtil instance p cannot be used to access the doStuff() method.Because dostuff() has protected access, and the ChildUtil class is not in the same package as the ParentUtil class.doStuff()can be accessed only by instance of the ChildUtil class(a subclass of ParentUtil).