1Z0-819 · Question #178
Given: public interface A { abstract void x(); } and public abstract class B / position 1 / { / position 2 / public void x() { } public abstract void z(); } and public class C extends B implements A…
The correct answer is D. public void z() {} // position 3. Option D works because class C inherits the concrete x() implementation from B, which satisfies interface A's requirement for x() - no additional code is needed for that. The only gap preventing C from compiling is B's abstract z() method, which a concrete subclass must…
Question
Options
- A@Override // position 3 public void x() {}
- B@Override // position 2 public void x() {}
- Cimplements A // position 3 public void z() {}
- Dpublic void z() {} // position 3
How the community answered
(35 responses)- A11% (4)
- B6% (2)
- C3% (1)
- D80% (28)
Explanation
Option D works because class C inherits the concrete x() implementation from B, which satisfies interface A's requirement for x() - no additional code is needed for that. The only gap preventing C from compiling is B's abstract z() method, which a concrete subclass must implement; placing public void z() {} at position 3 fulfills that obligation, making both B and C valid.
Why the distractors fail:
- A overrides
x()in C, which satisfies A'sx()contract but still leaves B's abstractz()unimplemented - C remains non-compilable. - B places
@Overrideonx()inside B itself, but B does not declare that itimplements A, so there is no supertype method being overridden - this is a compile error. - C attempts to insert
implements Ainside C's class body (position 3), which is illegal syntax;implementsbelongs only in the class declaration header, not the body.
Memory tip: Think of it as a checklist - every abstract method from every ancestor (class or interface) must be either implemented or re-declared abstract. Here, x() is already "checked off" by B's concrete method, so C's only unchecked item is z().
Topics
Community Discussion
No community discussion yet for this question.