+ 1

Chellange questions query

What is the output of this code? class A{ public: int f() { cout << 3; } int f(int x) { cout << x; } }; class B: public A{ public: int f() { cout << 5; } }; int main() { B ob; ob.f(7);} Output is compiled time error how??

18th Jun 2020, 3:38 PM
Poonam agarwal
Poonam agarwal - avatar
2 Answers
+ 1
the methods f are defined as ( int) but there is no return. you don't have to redefine f method in class B since it is inherited from A.
18th Jun 2020, 3:53 PM
Bahha┣
Bahha┣ - avatar
0
#include <iostream> using namespace std; class A{ public: void f() { cout << 3; } void f(int x) { cout << x; } }; class B: public A{ public: //void f(){ cout << 5; } }; int main() { B ob; ob.f(7); return 0; }
18th Jun 2020, 3:51 PM
Bahha┣
Bahha┣ - avatar