Bird
0
0

Which of the following is the correct syntax to declare a child class Dog that inherits from a parent class Animal?

easy📝 Syntax Q12 of 15
Java - Inheritance

Which of the following is the correct syntax to declare a child class Dog that inherits from a parent class Animal?

?
Aclass Dog implements Animal {}
Bclass Dog inherits Animal {}
Cclass Dog extends Animal {}
Dclass Dog Animal {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall Java class inheritance syntax

    In Java, the child class uses the keyword extends followed by the parent class name.
  2. Step 2: Match the correct syntax

    Only class Dog extends Animal {} is valid syntax for inheritance.
  3. Final Answer:

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

    Syntax for inheritance = extends [OK]
Quick Trick: Use 'extends' keyword to link child and parent classes [OK]
Common Mistakes:
  • Using 'inherits' which is not a Java keyword
  • Using 'implements' which is for interfaces
  • Omitting the keyword between class names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes