Which feature of OOP is indicated by the following code?

Asked In: BPSC TRE 3.0
class student{  int marks;  };
class topper:public student{  int age;  topper(int age){ this.age=age; } };
                        

Options

  • A. Polymorphism
  • B. Inheritance
  • C. Inheritance and polymorphism
  • D. Encapsulation and Inheritance

Correct Answer (Detailed Explanation is Below)

B. Inheritance

Detailed Explanation

Explanation:

In the given code:
The line:
class topper : public student

shows that topper is inheriting from student.

This clearly indicates the OOP feature Inheritance.

There is:

  • ❌ No method overriding → so no Polymorphism

  • ❌ No special data hiding logic shown → so not specifically Encapsulation

In C++, inheritance is written using : followed by the access specifier and base class.