Complete the code to declare that Dog is a type of Animal using inheritance.
class Animal {} class Dog : [1] {}
In C#, to show that Dog is a type of Animal, Dog must inherit from Animal using a colon and the base class name.
Complete the code to override the Speak method in the Dog class.
class Animal { public virtual void Speak() { Console.WriteLine("Animal sound"); } } class Dog : Animal { public override void [1]() { Console.WriteLine("Bark"); } }
The Dog class overrides the Speak method from Animal. The method name must match exactly to override it.
Fix the error in the code by completing the inheritance declaration.
class Vehicle {} class Car [1] Vehicle { public void Drive() { Console.WriteLine("Driving"); } }
In C#, inheritance is declared using a colon (:), not words like 'inherits' or 'extends'.
Complete the code to create a class Cat that inherits from Animal and overrides the Speak method.
class Animal { public virtual void Speak() { Console.WriteLine("Animal sound"); } } class Cat : Animal { public [1] void Speak() { Console.WriteLine("Meow"); } }
The Cat class inherits from Animal using a colon (:). The Speak method overrides the base method using the override keyword.
Fill both blanks to define a class Bird that inherits from Animal, overrides Speak, and calls the base Speak method inside it.
class Animal { public virtual void Speak() { Console.WriteLine("Animal sound"); } } class Bird : Animal { public [1] void Speak() { [2].Speak(); Console.WriteLine("Chirp"); } }
Bird inherits from Animal using ':'. It overrides Speak with 'override'. Inside Speak, it calls the base class method using 'base.Speak()'.