Recall & Review
beginner
What is an abstract class in C#?An abstract class is a class that cannot be instantiated directly. It is designed to be a base class for other classes and can contain abstract methods that must be implemented by derived classes.Click to reveal answer
beginner
What is an abstract method?
An abstract method is a method declared in an abstract class without an implementation. Derived classes must provide their own implementation of this method.Click to reveal answer
beginner
Can you create an object of an abstract class?
No, you cannot create an object of an abstract class directly. You must create an object of a derived class that implements all abstract methods.Click to reveal answer
intermediate
Why use abstract classes and methods?
They help define a common template for related classes, ensuring that certain methods are implemented in all derived classes, promoting code consistency and reuse.
Click to reveal answer
beginner
Show a simple example of an abstract class with an abstract method in C#.abstract class Animal {
public abstract void MakeSound();
}
class Dog : Animal {
public override void MakeSound() {
System.Console.WriteLine("Woof!");
}
}Click to reveal answer
Which keyword is used to declare an abstract class in C#?
✗ Incorrect
The keyword 'abstract' is used to declare an abstract class.
Can an abstract method have a body (implementation) in C#?
✗ Incorrect
Abstract methods cannot have an implementation; they only declare the method signature.
What must a derived class do with an abstract method?
✗ Incorrect
Derived classes must override and provide an implementation for all abstract methods.
Can you instantiate an abstract class directly?
✗ Incorrect
Abstract classes cannot be instantiated directly.
Which of these is true about abstract classes?
✗ Incorrect
Abstract classes can have both abstract methods and methods with implementations.
Explain what an abstract class and an abstract method are, and why they are useful.
Think about how you create a blueprint for other classes.
You got /4 concepts.
Write a simple C# example showing an abstract class with one abstract method and a derived class implementing that method.
Use Animal and Dog as example classes.
You got /4 concepts.