Multiple choice

What is the output of C++ program given below?

#include<iostream> using namespace std; class Test { public: int a=9; void func() { cout<<a*a; }
}; class Hello:public Test { public: void func(int x) { cout<<a*x; } }; int main() { Hello obj; obj.func(5); }

  1. 81

  2. 45

  3. 25

  4. Error in the program

  5. None of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

  Concept involved here in the program is function overloading. func is the signature common of the method which is present in both Test (parent class) & Hello (base class). But both vary in number of parameter which distinguishes them.

obj.func(5) which calls func(int x) hence output will be computed as follows: a*x=9*5=45 This option is true.