Hi,
package testpkg.p1;
public class ParentUtil {
public int x = 420;
protected int doStuff() { return x; }
}
package testpkg.p2;
import testpkg.p1.ParentUtil;
public class ChildUtil extends ParentUtil {
public static void main(
String [] args) {
new ChildUtil().callStuff();
}
void callStuff() {
System.out.print("this " + this.doStuff() );
ParentUtil p = new ParentUtil();
System.out.print(" parent " + p.doStuff() );
}
}
which statement is true?
1. The code compiles and runs, with output this 420 parent 420.
2.If line 8 is removed, the code will compile and run.
3.If line 10 is removed, the code will compile and run.
4.Both lines 8 and 10 must be removed for the code to compile.
5.An exception is thrown at runtime.
The answer ios 3....Why? Can anybody explain me. I thought the answer was 1.
Thanks.