Bird
0
0

Examine the code below and identify the compilation error:

medium📝 Debug Q6 of 15
Java - Abstraction
Examine the code below and identify the compilation error:
abstract class Appliance {
    abstract void operate();
}
class Washer extends Appliance {
    void operate() {
        System.out.println("Washing clothes");
    }
}
class Dryer extends Appliance {
}
public class Test {
    public static void main(String[] args) {
        Appliance d = new Dryer();
        d.operate();
    }
}
AMethod operate() in Washer should be abstract
BCannot instantiate abstract class Dryer
CClass Dryer must implement the abstract method operate()
DNo error, code compiles and runs successfully
Step-by-Step Solution
Solution:
  1. Step 1: Identify abstract class and methods

    Class Appliance has an abstract method operate().
  2. Step 2: Check subclass implementations

    Class Washer implements operate(), but Dryer does not.
  3. Step 3: Understand Java rules

    Any concrete subclass must implement all abstract methods or be declared abstract.
  4. Final Answer:

    Class Dryer must implement the abstract method operate() -> Option C
  5. Quick Check:

    Concrete subclasses must implement all abstract methods. [OK]
Quick Trick: Concrete subclass must implement all abstract methods [OK]
Common Mistakes:
  • Assuming abstract methods can be left unimplemented in concrete classes
  • Thinking abstract classes can be instantiated
  • Believing overriding methods must be abstract

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes