Bird
0
0

Which of the following is the correct syntax to inherit class Animal in Java?

easy📝 Syntax Q12 of 15
Java - Inheritance
Which of the following is the correct syntax to inherit class Animal in Java?
Aclass Dog inherits Animal {}
Bclass Dog extends Animal {}
Cclass Dog implements Animal {}
Dclass Dog uses Animal {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall Java inheritance syntax

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

    class Dog extends Animal {} uses extends, which is correct. Options A, C, and D use wrong keywords.
  3. Final Answer:

    class Dog extends Animal {} -> Option B
  4. Quick Check:

    Inheritance keyword = extends [OK]
Quick Trick: Use 'extends' keyword to inherit a class in Java [OK]
Common Mistakes:
  • Using 'inherits' instead of 'extends'
  • Confusing 'implements' with class inheritance
  • Using 'uses' keyword which doesn't exist

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes