+ 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??
2 Respuestas
+ 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.
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;
}