Which feature of OOP is indicated by the following code?
2023
Which feature of OOP is indicated by the following code?
- A.
Encapsulation and inheritance
- B.
Inheritance and polymorphism
- C.
Polymorphism
- D.
More than one of the above
- E.
None of the above
Attempted by 296 students.
Show answer & explanation
Correct answer: A
The given code demonstrates two key features of Object-Oriented Programming (OOP): Encapsulation: The 'marks' variable in the 'student' class is declared as private, which restricts direct access and ensures data hiding. Inheritance: The 'topper' class inherits from the 'student' class using 'public student', allowing it to access public members of the base class. Polymorphism is not demonstrated as there are no virtual functions or function overriding.