Wk7-12 Content Flashcards
What is inheritance in C++?
A feature that allows a class (derived) to inherit properties and behavior from another class (base).
How is a class declared as a derived class in C++?
By using the syntax: class DerivedClass : accessSpecifier BaseClass.
What is polymorphism in C++?
The ability of objects of different classes to respond differently to the same function call.
What is virtual function in C++?
A function declared in the base class using the keyword ‘virtual’ and is redefined by the derived class.
How does virtual function support polymorphism?
It allows derived classes to override the base class method implementation.
What is the significance of the ‘protected’ access specifier?
Protected members are accessible within the class, its derived classes, but not outside of them.
Why is inheritance used in C++, and what are its benefits?
For code reusability and to establish a relationship between classes.
What is multiple inheritance?
A feature where a class can inherit from more than one base class.
What are the risks of multiple inheritance?
It can lead to ambiguities and complexity, especially with diamond problem.
How is the ‘override’ keyword used in C++?
It ensures that the function is overriding a virtual function from a base class.
What is an abstract class?
A class that cannot be instantiated and usually contains at least one pure virtual function.
How do you declare a pure virtual function?
By assigning 0 to the virtual function: virtual void function() = 0;
What is the ‘final’ specifier in C++?
It prevents a class from being inherited or a virtual function from being overridden.
How can constructors and destructors be inherited?
Through the use of inheritance, constructors and destructors are called for both base and derived classes.
What is static polymorphism?
It is resolved at compile time, e.g., function overloading and templates.
What is dynamic polymorphism?
It is resolved at runtime, e.g., through the use of virtual functions.
How does the ‘this’ pointer relate to inheritance?
It refers to the current object instance, and is used within class methods to refer to the object.
What is the ‘super’ or ‘base’ keyword used for in inheritance?
It is used to refer to the base class, often used in derived class constructors.
What is method overriding in C++?
Replacing a base class method in a derived class with a new implementation.
What is a virtual destructor?
A destructor that is declared virtual in the base class to ensure proper resource release.
How does C++ handle constructor inheritance?
Derived class constructors call base class constructors implicitly or explicitly.
What is the role of UML in OOP?
Unified Modeling Language, it visually represents the design of an OOP system.
How are class relationships represented in UML?
Through various types of lines and arrows, indicating relationships like inheritance and association.
What is the diamond problem in inheritance?
A problem that arises when two classes separately inherit from the same base class and are combined into another class.