Bird
Raised Fist0

Which of the following is the correct syntax to declare a class Dog that inherits from class Animal in C#?

easy📝 Syntax Q3 of Q15
C Sharp (C#) - Inheritance
Which of the following is the correct syntax to declare a class Dog that inherits from class Animal in C#?
Aclass Dog inherits Animal {}
Bclass Dog : Animal {}
Cclass Dog extends Animal {}
Dclass Dog implements Animal {}
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct inheritance syntax in C#

    C# uses ':' to declare inheritance, so 'class Dog : Animal {}' is correct.
  2. Step 2: Eliminate incorrect keywords

    'inherits', 'extends', and 'implements' are not valid for class inheritance in C#.
  3. Final Answer:

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

    Correct inheritance syntax = ':' [OK]
Quick Trick: Use ':' to inherit classes in C# [OK]
Common Mistakes:
MISTAKES
  • Using Java keywords like 'extends'
  • Using 'implements' for class inheritance
  • Writing 'inherits' which is not a keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes