Complete the code to declare an abstract class named Animal.
public [1] class Animal { public abstract void Speak(); }
The keyword abstract is used to declare an abstract class in C#.
Complete the code to declare an abstract method Speak inside the abstract class Animal.
public abstract class Animal { public [1] void Speak(); }
The abstract keyword declares a method without implementation inside an abstract class.
Fix the error in the derived class Dog that does not implement the abstract method Speak.
public class Dog : Animal { public [1] void Speak() { Console.WriteLine("Woof!"); } }
The derived class must use override to implement the abstract method from the base class.
Fill both blanks to declare an abstract class Vehicle and an abstract method Move.
public [1] class Vehicle { public [2] void Move(); }
The class must be declared abstract and the method abstract to be incomplete and require implementation in derived classes.
Fill all three blanks to implement an abstract class Shape with an abstract method Area and a derived class Circle overriding Area.
public [1] class Shape { public [2] double Area(); } public class Circle : Shape { private double radius; public Circle(double r) { radius = r; } public [3] double Area() { return Math.PI * radius * radius; } }
The class Shape and its method Area are declared abstract. The Circle class overrides the Area method to provide implementation.