Which feature of OOP is indicated by the following code?
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:
In C++, inheritance is written using : followed by the access specifier and base class.