Bird
0
0

Which of the following is the correct way to inherit class Vehicle in Java?

easy📝 Syntax Q3 of 15
Java - Inheritance
Which of the following is the correct way to inherit class Vehicle in Java?
Aclass Car extends Vehicle {}
Bclass Car inherits Vehicle {}
Cclass Car Vehicle {}
Dclass Car : Vehicle {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall Java inheritance syntax

    Java uses the keyword extends to inherit a class.
  2. Step 2: Check each option

    Only class Car extends Vehicle {} uses extends correctly; others use invalid keywords or syntax.
  3. Final Answer:

    class Car extends Vehicle {} -> Option A
  4. Quick Check:

    Inheritance syntax = extends keyword [OK]
Quick Trick: Use 'extends' keyword to inherit a class in Java [OK]
Common Mistakes:
  • Using 'inherits' instead of 'extends'
  • Omitting 'extends' keyword
  • Using ':' like in other languages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes