Function Overloading in C++
15 questions · 12 min · Medium
Test your knowledge of inheritance in C++, including base and derived classes, types of inheritance, access specifiers, constructor and destructor behavior, overriding, and multiple inheritance.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
20 questions · 15 min · Medium
15 questions · 12 min · Medium
A. A mechanism that allows a class to acquire properties and behavior from another class
Inheritance allows a derived class to reuse and extend members of a base class.
A. Derived class
A derived class inherits members and behavior from a base class.
A. :
A colon is placed after the derived class name to specify its base class and inheritance access, such as class Dog : public Animal.
A. class Dog : public Animal { };
C++ specifies inheritance using a colon followed by an access specifier and the base class name.
A. Single inheritance
Single inheritance occurs when one derived class inherits from one base class.
A. A derived class inherits from more than one base class
Multiple inheritance allows a single derived class to inherit from two or more base classes.
A. protected
Protected members are accessible within the class itself and its derived classes, subject to C++ access rules.
A. They remain public in the derived class
With public inheritance, public base-class members remain public in the derived class.
A. They become private members of the derived class
Under private inheritance, public and protected members inherited from the base class become private members of the derived class.
A. Base class constructor, then derived class constructor
When a derived object is created, its base-class subobjects are initialized before the derived class constructor body runs.
A. Derived class destructor, then base class destructor
Destruction occurs in reverse order of construction, so the derived destructor runs before the base class destructor.
A. Providing a derived-class implementation of a virtual function declared in a base class
A derived class can override a virtual function from its base class to provide specialized behavior.
A. virtual
The virtual keyword enables dynamic dispatch for a member function when accessed through a suitable base-class interface.
A. override
The override specifier tells the compiler that the derived-class function is intended to override a virtual function from a base class.
A. Multiple derived classes inherit from the same base class
Hierarchical inheritance occurs when two or more derived classes inherit from a common base class.