ProgrammingHardHCL · Tech Mahindra pattern

Which statement is correct?

Which statement is correct?
interface Shape {
    double area();
}
abstract class AbstractShape implements Shape {
    public abstract double area();
    public String describe() { return "Area: " + area(); }
}
class Circle extends AbstractShape {
    double r = 2;
    public double area() { return 3.14 * r * r; }
}
  1. A. It fails to compile: AbstractShape must implement area(), not redeclare it abstract
  2. B. It compiles fine; an abstract class may redeclare an inherited abstract method as abstract (a no-op), deferring the real implementation to a concrete subclass
  3. C. It compiles only if AbstractShape is declared final
  4. D. It fails to compile because describe() calls an unimplemented method

Correct answer: B. It compiles fine; an abstract class may redeclare an inherited abstract method as abstract (a no-op), deferring the real implementation to a concrete subclass

Redeclaring an interface method as abstract inside an abstract class is legal and common (sometimes done just to add stricter Javadoc or re-affirm the contract) — it changes nothing structurally since the class is already abstract. Circle, being concrete, must and does supply a real area().

More OOP with C++ and Java questions

Exams that ask this topic