Given:
Which statement is true?
A.
Both p and s are accessible by obj.
B.
Only s is accessible by obj.
C.
Both r and s are accessible by obj.
D.
p, r, and s are accessible by obj.
Given:
Which statement is true?
A.
Both p and s are accessible by obj.
B.
Only s is accessible by obj.
C.
Both r and s are accessible by obj.
D.
p, r, and s are accessible by obj.
C
Answer: B
package q076;
public class Acc {
int p;
private int q;
protected int r = 9;
public int s = 10;
}
package q075;
import q076.Acc;
public class Test extends Acc {
public static void main(String[] args) {
Acc obj = new Test();
System.out.println(“p = “+obj.p +”s = “+obj.s +” r = “+ obj.r);
System.out.println(“Only s is visible: => child.member with protected modifier”);
}
}
/* Output:
Exception in thread “main” java.lang.Error: Unresolved compilation problems:
The field Acc.p is not visible
The field Acc.r is not visible
at q075.Test.main(Test.java:8)
*/
Only child reference is allowed.
B