Discussion
class C {
public:
void f(int a) {cout \(\lt\lt\) a;}
void f(int a, int b) {cout \(\lt\lt\) a+b;};
void f(int a, int b, int c) {cout \(\lt\lt\) a+b+c;}
};
int main( )
{
C obj;
obj.f(10);
obj.f(10, 20);
obj.f(10, 20, 30);
return 0;
}
The above C++ source code exemplifies which of the following principle with respect to object-oriented programming ?
Answer: D
The code exemplifies polymorphism.
Class C defines three member functions with the same name f but different parameter lists. The compiler selects the right one from the arguments at each call, which is function overloading, a form of compile-time (static) polymorphism. The program prints 10, then 30, then 60.
Nothing here hides implementation details behind an interface (abstraction) or bundles data with access control as the point of the example (encapsulation), and there is no base or derived class, so it is not inheritance.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development