Bird
0
0

Find the error in this inheritance code:

medium📝 Debug Q14 of 15
Java - Inheritance
Find the error in this inheritance code:
class Vehicle {
  void start() { System.out.println("Vehicle started"); }
}
class Car Vehicle {
  void start() { System.out.println("Car started"); }
}
AClass Vehicle should be abstract
BMissing semicolon after class Vehicle
CMethod start() cannot be overridden
DIncorrect inheritance syntax in class Car
Step-by-Step Solution
Solution:
  1. Step 1: Check class inheritance syntax

    In Java, to inherit a class, use extends keyword. The code misses extends in class Car Vehicle.
  2. Step 2: Verify other options

    No semicolon needed after class declaration, methods can be overridden, and Vehicle need not be abstract.
  3. Final Answer:

    Incorrect inheritance syntax in class Car -> Option D
  4. Quick Check:

    Use 'extends' keyword for inheritance [OK]
Quick Trick: Inheritance needs 'extends' keyword in class declaration [OK]
Common Mistakes:
  • Forgetting 'extends' keyword
  • Adding semicolon after class header
  • Thinking methods can't be overridden

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes