In this quiz, we will explore the key concepts of C# abstract classes. Abstract classes are a fundamental feature in object-oriented programming, providing a way to create templates for other classes. These classes allow for defining abstract methods that must be implemented by any subclass while also supporting virtual methods with default functionality. This quiz will test your understanding of abstract classes, inheritance, method overriding, and how these concepts contribute to creating structured, efficient, and reusable code in C#.
1.
What is a C# abstract class?
2.
What is the key characteristic of an abstract member in a C# abstract class?
3.
How do you declare an abstract class in C#?
4.
Which keyword is used to implement an abstract member in a subclass?
5.
What will happen if a subclass does not implement all abstract members from its abstract base class?
6.
What is the role of the 'base' keyword in a subclass?
7.
What is a virtual method in C#?
8.
What is the difference between an abstract and a virtual member in a C# abstract class?
9.
In the following code, what happens if you call the 'Goodbye' method from a 'SayHello' instance?
class SayHello : Talk
{
public override void Goodbye()
{
Console.WriteLine('Goodbye from SayHello class');
}
}
10.
Can an abstract class have non-abstract methods?
11.
Which of the following is true about abstract classes?
12.
What is the primary purpose of using abstract classes in C#?
13.
When must a subclass use the 'override' keyword?
14.
Can you instantiate an object of an abstract class directly?
15.
In the following code, which method will be called when the 'Goodbye' method is invoked?
public class Talk
{
public virtual void Goodbye()
{
Console.WriteLine('Goodbye from Talk');
}
}
public class SayHello : Talk
{
public override void Goodbye()
{
Console.WriteLine('Goodbye from SayHello');
}
}