Govt. Exams
Entrance Exams
Abstract classes define a contract (interface) that derived classes must implement. This ensures consistency and enables polymorphic behavior across different derived classes.
A pure virtual function (defined with = 0) must be overridden in derived classes. The base class containing it becomes abstract and cannot be instantiated.
Proper encapsulation hides data members (private) and provides controlled access through public getter and setter methods.
A copy constructor takes a reference to another object of the same class and creates a copy of it. Syntax: ClassName(const ClassName &obj);
Multiple inheritance can lead to the Diamond Problem where a class inherits from two classes that share a common base. This is solved using virtual inheritance.
C++ doesn't have a dedicated 'abstract' keyword. Abstract classes are created by defining at least one pure virtual function (virtual func() = 0;). You cannot instantiate abstract classes.
Method overloading occurs in the same class with different parameter lists (compile-time polymorphism). Method overriding occurs in derived classes with the same signature (runtime polymorphism).
class Base {
public:
virtual void display() { cout
Due to virtual function and dynamic polymorphism, the Derived class's display() method is called because the actual object is of type Derived, even though the pointer is of type Base.
Constructor overloading allows multiple constructors with different parameter lists. Option A is correct as it has constructors with no parameters and with an int parameter.