nerdexam
Oracle

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…

Java Object-Oriented Approach

Question

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 { / position 3 */ } Which code, when inserted at one or more marked positions, would allow classes B and C to compile?

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)
  • A
    11% (4)
  • B
    6% (2)
  • C
    3% (1)
  • D
    80% (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's x() contract but still leaves B's abstract z() unimplemented - C remains non-compilable.
  • B places @Override on x() inside B itself, but B does not declare that it implements A, so there is no supertype method being overridden - this is a compile error.
  • C attempts to insert implements A inside C's class body (position 3), which is illegal syntax; implements belongs 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

#abstract classes#interface implementation#method inheritance#concrete classes

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice