Bird
0
0

Identify the error in the following code snippet:

medium📝 Debug Q14 of 15
Java - Abstraction

Identify the error in the following code snippet:

abstract class Vehicle {
    abstract void move();
}

class Car extends Vehicle {
    void start() {
        System.out.println("Car started");
    }
}
ACar class must implement the move() method or be abstract.
BVehicle class cannot have abstract methods.
CCar class cannot have methods other than move().
DNo error, code is correct.
Step-by-Step Solution
Solution:
  1. Step 1: Check abstract method implementation

    Vehicle declares abstract method move(). Any concrete subclass must implement it or be declared abstract.
  2. Step 2: Analyze Car class

    Car does not implement move() and is not abstract, so this causes a compilation error.
  3. Final Answer:

    Car class must implement the move() method or be abstract. -> Option A
  4. Quick Check:

    Concrete subclass must implement all abstract methods [OK]
Quick Trick: Concrete subclass must implement all abstract methods [OK]
Common Mistakes:
  • Forgetting to implement abstract methods in subclass
  • Thinking abstract class can't have abstract methods
  • Believing subclass can skip abstract methods without being abstract

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes