189k views
5 votes
You already have a class to store lab test results. You overload the __ operator to return True if both patients have a cholesterol level over 225. This is an example of ___________.

A/ instantiation
B. inheritance
C. polymorphism
D. encapsulation

User Bolster
by
7.9k points

1 Answer

3 votes

Final answer:

Overloading the __lt__ operator in a class for comparing cholesterol levels is an example of polymorphism, which is applying different behaviors in different contexts using the same operation.

Step-by-step explanation:

Overloading the __lt__ operator in a class to compare cholesterol levels is an example of polymorphism.

Polymorphism is a concept in object-oriented programming that allows objects to be processed in different ways depending on their data type or class. In the context of this question, overloading allows objects representing lab test results to be compared using a custom definition of what it means for one patient to have a higher cholesterol level than another. This provides the flexibility to define what the comparison operator __lt__ should do when applied to objects of the lab test result class.

In this case, rather than using the operator in the traditional numerical sense, it is used to evaluate a boolean condition. If both patients have a cholesterol level over 225, the operator returns True. This kind of operator overloading is a practical demonstration of polymorphism, as it involves an operator taking on a different meaning or action depending on the context of the operand (in this case, the object representing a patient's lab test results).

User Brian David Berman
by
7.9k points