Class B in package q extends class A in package p, and A declares protected int n. Inside an instance method of B, which expression fails to compile?
Correct answer B. new A().n
Explanation
Outside its package, a protected member can be accessed only through a reference whose type is the subclass doing the access, or one of its subclasses. The forms n, this.n and super.n all work on the current B object. The expression new A().n uses a plain A reference, so the compiler rejects it.
Answer checked How we write and check questions
Discussion