Question 1: Please answer the following sub questions
1.1) Why is it important to create C++ abstract
virtual class?
1.2) Why would I want to use a C++ abstract virtual class?
1.3) Why override methods of C++ abstract virtual class and not
just create them?
1.1)
The purpose of an abstract class is to define a common protocol for a set of concrete subclasses. This is useful when defining objects that share code, abstract ideas, etc.
Abstract classes have no instances. An abstract class must have at least one deferred method (or function). To accomplish this in C++, a pure virtual member function is declared but not defined in the abstract class.
1.2)Abstract classes are used to provide an Interface for its sub classes. Classes inheriting an Abstract Class must provide definition to the pure virtual function, otherwise they will also become abstract class.Abstract classes are used to represent general concepts (for example, Shape, Animal), which can be used as base classes for concrete classes (for example, Circle, Dog).
1.3)If we do not override the pure virtual function in derived class, then derived class also becomes abstract class.
Get Answers For Free
Most questions answered within 1 hours.