Govt. Exams
Entrance Exams
The Diamond Problem occurs when a class inherits from two classes that both inherit from a common base class, creating ambiguity in the inheritance hierarchy.
class Base { public: void display() { cout
Since 'display()' is not virtual and obj is of type Base, it calls Base::display(). Object slicing occurs when a Derived object is assigned to Base reference.
The 'final' keyword (introduced in C++11) prevents further overriding of a virtual function in derived classes.
For non-virtual functions, the function call is resolved based on the pointer type (base class), not the actual object type. Therefore, the base class version is called.
A const member function cannot modify the state of the object (its member variables). It's used to indicate that a function only reads data without changing it.
Encapsulation bundles data and functions together, hiding implementation details using access specifiers (private, protected, public) and controlling how external code interacts with the object.
Method overloading is resolved at compile-time (static polymorphism) with different function signatures, while method overriding is resolved at runtime (dynamic polymorphism) using virtual functions.
class A {
public:
A() { cout
When a derived class object is created, the base class constructor is called first, then the derived class constructor. Output is 'A B'.
An abstract class in C++ is defined by having at least one pure virtual function (declared with = 0). Objects cannot be instantiated from abstract classes.
class Base {
public:
virtual void display() { cout
Due to virtual function and runtime polymorphism, the Derived class's display() method is called through the Base class pointer, printing 'Derived'.