Complete the code to declare a sealed class named 'Vehicle'.
public [1] class Vehicle { public void Start() { } }
The keyword sealed prevents other classes from inheriting from this class.
Complete the code to prevent overriding of the 'Drive' method in derived classes.
public class Car { public virtual void Drive() { } } public class SportsCar : Car { public [1] override void Drive() { } }
The sealed keyword on an override method stops further overriding in subclasses.
Fix the error in the code by completing the class declaration to prevent inheritance.
public class BaseClass { } public [1] class DerivedClass : BaseClass { }
Marking 'DerivedClass' as sealed prevents other classes from inheriting from it.
Fill both blanks to declare a sealed class and a sealed override method.
public class Animal { public virtual void Speak() { } } public [1] class Dog : Animal { public [2] override void Speak() { } }
The class 'Dog' is sealed to prevent inheritance, and the 'Speak' method in 'Dog' is sealed to prevent further overrides.
Fill all three blanks to create a sealed class, a sealed override method, and call the base method.
public class Shape { public virtual void Draw() { Console.WriteLine("Drawing shape"); } } public [1] class Circle : Shape { public [2] override void Draw() { base.[3](); Console.WriteLine("Drawing circle"); } }
The class 'Circle' is sealed to prevent inheritance. The 'Draw' method in 'Circle' is sealed to prevent further overrides. The base method 'Draw' is called inside the override.