Bird
0
0

Find the error in this code:

medium📝 Debug Q7 of 15
Java - Inheritance

Find the error in this code:

abstract class Vehicle {
    abstract void start();
}

class Car extends Vehicle {
    void start() { System.out.println("Car started"); }
}

class Bike extends Vehicle {
    // No start() method implemented
}
ANo error, code is correct
BCar cannot override start() method
CVehicle cannot be abstract
DBike must implement start() or be declared abstract
Step-by-Step Solution
Solution:
  1. Step 1: Understand abstract class rules

    Abstract classes can have abstract methods that must be implemented by subclasses.
  2. Step 2: Check subclass implementations

    Car implements start(), but Bike does not implement start() and is not abstract, causing error.
  3. Final Answer:

    Bike must implement start() or be declared abstract -> Option D
  4. Quick Check:

    Abstract methods require implementation [OK]
Quick Trick: Abstract methods must be implemented or subclass abstract [OK]
Common Mistakes:
  • Ignoring abstract method implementation
  • Assuming abstract class can't have abstract methods
  • Thinking subclasses can skip abstract methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes