Complete the code to declare an abstract class in C#.
public [1] class Animal { public abstract void Speak(); }
The keyword abstract is used to declare an abstract class in C#.
Complete the code to create a concrete class that inherits from an abstract class.
public class Dog : Animal { public override void [1]() { Console.WriteLine("Woof!"); } }
The concrete class Dog must override the abstract method Speak from the base class.
Fix the error in the code by choosing the correct keyword for the class.
public [1] class Vehicle { public void Start() { Console.WriteLine("Starting vehicle"); } }
The class is intended to be a concrete class that cannot be inherited, so sealed is the correct keyword.
Fill both blanks to define an abstract method and a concrete method in an abstract class.
public abstract class Shape { public abstract double [1](); public double [2]() { return 0; } }
The abstract method Area must be implemented by subclasses, while Perimeter is a concrete method with a default implementation.
Fill all three blanks to create a concrete class that implements abstract methods and adds a new method.
public class Circle : Shape { public override double [1]() { return 3.14 * radius * radius; } public override double [2]() { return 2 * 3.14 * radius; } public double [3]() { return radius; } private double radius; public Circle(double r) { radius = r; } }
The class Circle overrides the abstract methods Area and Perimeter from Shape and adds a new method GetRadius.