Which feature of OOP is indicated by the following code?

Asked In: BPSC TRE 1.0
class student { int marks; };
class topper : public student {
    int age;
    topper(int age) { this->age = age; }
};
                        

Options

  • A. Encapsulation and inheritance
  • B. Inheritance and polymorphism
  • C. Polymorphism only
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. Encapsulation and inheritance

Detailed Explanation

Correct Answer: Option A

Explanation:
The class student groups the data member marks inside a class, demonstrating encapsulation. The declaration class topper : public student shows public inheritance, meaning topper derives from student. No function overriding or runtime polymorphism is demonstrated. Note: the constructor is private by default here because topper is declared using class and has no public: label, but this does not change the intended answer.