Recall & Review
beginner
What is an abstract class in C++?An abstract class is a class that cannot be instantiated on its own and usually contains at least one pure virtual function. It serves as a blueprint for other classes.Click to reveal answer
beginner
What is a pure virtual function?
A pure virtual function is a function declared by assigning 0 in its declaration (e.g.,
virtual void func() = 0;). It must be overridden by derived classes.Click to reveal answer
beginner
Why can't you create an object of an abstract class?
Because abstract classes have pure virtual functions without implementations, the compiler prevents creating objects to ensure derived classes provide those implementations.
Click to reveal answer
beginner
How do you declare a pure virtual function in C++?
By adding
= 0 at the end of the function declaration inside the class, for example: virtual void draw() = 0;.Click to reveal answer
intermediate
What happens if a derived class does not override all pure virtual functions?The derived class also becomes abstract and cannot be instantiated until it overrides all pure virtual functions from its base classes.Click to reveal answer
Which keyword is used to declare a pure virtual function in C++?
✗ Incorrect
A pure virtual function is declared by adding '= 0' at the end of its declaration.
Can you create an object of an abstract class?
✗ Incorrect
Abstract classes cannot be instantiated because they have pure virtual functions without implementations.
What must a derived class do if its base class has a pure virtual function?
✗ Incorrect
Derived classes must override all pure virtual functions to become concrete and instantiable.
What happens if a derived class does not override a pure virtual function?
✗ Incorrect
If a derived class does not override all pure virtual functions, it remains abstract and cannot be instantiated.
Which of these is true about abstract classes?
✗ Incorrect
Abstract classes can have both implemented and pure virtual functions.
Explain what an abstract class is and why it is useful in C++.
Think about classes that define rules but don't create objects directly.
You got /4 concepts.
Describe how pure virtual functions enforce behavior in derived classes.
Consider how a base class can require derived classes to provide specific functions.
You got /4 concepts.