0
0
C Sharp (C#)programming~10 mins

Why inheritance is needed in C Sharp (C#) - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a class Dog that inherits from Animal.

C Sharp (C#)
class Dog : [1] { }
Drag options to blanks, or click blank then click option'
ADog
BBase
CAnimal
DObject
Attempts:
3 left
💡 Hint
Common Mistakes
Using the child class name instead of the parent class name.
Using a keyword like 'Base' which is not a class name.
2fill in blank
medium

Complete the code to call the base class constructor from the derived class Car.

C Sharp (C#)
class Car : Vehicle {
    public Car() : [1]() { }
}
Drag options to blanks, or click blank then click option'
Abase
Bthis
Csuper
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'this' instead of 'base' to call the base constructor.
Using 'super' which is not a C# keyword.
3fill in blank
hard

Fix the error in the code to override the Speak method in the derived class Cat.

C Sharp (C#)
class Cat : Animal {
    public override void [1]() {
        Console.WriteLine("Meow");
    }
}
Drag options to blanks, or click blank then click option'
Aspeak
BSpeak
CSay
DTalk
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'speak' instead of 'Speak'.
Using a different method name like 'Say' or 'Talk'.
4fill in blank
hard

Fill both blanks to create a derived class Bird that inherits from Animal and overrides the Move method.

C Sharp (C#)
class Bird : [1] {
    public override void [2]() {
        Console.WriteLine("Flying");
    }
}
Drag options to blanks, or click blank then click option'
AAnimal
BMove
CFly
DSpeak
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong base class name.
Overriding a method with a wrong name.
5fill in blank
hard

Fill all three blanks to create a dictionary that maps animal names to their sounds using inheritance concepts.

C Sharp (C#)
var sounds = new Dictionary<string, string> {
    { [1], [2] },
    { [3], "Bark" }
};
Drag options to blanks, or click blank then click option'
A"Cat"
B"Meow"
C"Dog"
D"Purr"
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping keys and values.
Using incorrect string quotes.