nerdexam
Oracle

1Z0-809 · Question #62

Given the following abstract class Shape: ``java public abstract class Shape { private int x; private int y; public abstract void draw(); public void setAnchor(int x, int y) { this.x = x; this.y =…

The correct answer is B. public abstract class Circle extends Shape { Private int radius; } E. public class Circle extends Shape { Private int radius; public void draw() { /* code here */ } }. B and E are correct because Shape is an abstract class, not an interface - this means subclasses must use extends, not implements. Option B is valid because a class declared abstract is not required to implement inherited abstract methods (it defers that responsibility to its…

Question

Given the following abstract class Shape:
public abstract class Shape {
 private int x;
 private int y;
 public abstract void draw();
 public void setAnchor(int x, int y) {
 this.x = x;
 this.y = y;
 }
}
Which two classes use the shape class correctly?

Options

  • Apublic abstract class Circle implements Shape { Private int radius; }
  • Bpublic abstract class Circle extends Shape { Private int radius; }
  • Cpublic class Circle extends Shape { Private int radius; public void draw(); }
  • Dpublic abstract class Circle implements Shape { private int radius; public void draw(); }
  • Epublic class Circle extends Shape { Private int radius; public void draw() { /* code here */ } }
  • Fpublic abstract class Circle implements Shape { private int radius; public void draw() { /* code here */ } }

How the community answered

(29 responses)
  • A
    3% (1)
  • B
    72% (21)
  • C
    14% (4)
  • D
    3% (1)
  • F
    7% (2)

Explanation

B and E are correct because Shape is an abstract class, not an interface - this means subclasses must use extends, not implements. Option B is valid because a class declared abstract is not required to implement inherited abstract methods (it defers that responsibility to its own subclasses). Option E is valid because it's a concrete class that properly implements draw() with a method body, satisfying the contract imposed by the abstract parent.

Why the distractors fail:

  • A, D, F - all use implements Shape, which is illegal; you implement interfaces and extend classes. Since Shape is an abstract class, this is a compile-time error.
  • C - writes public void draw(); with no body in a concrete class. A method signature without a body is only legal in an interface or when explicitly marked abstract. A concrete class extending an abstract parent must provide a full implementation.

Memory tip: "Classes extend, interfaces implement." When you see abstract class in the question, immediately cross out every answer that says implements - you've already eliminated half the wrong choices.

Community Discussion

No community discussion yet for this question.

Full 1Z0-809 Practice