obj?

Which code, inserted at line 5, generates the output "ABC"?

#include <iostream>

using namespace std;

class A {

public:

//insert code here

};

class B:public A {

public:

void Print(){ cout<< "B"; }

};

class C:public B {

public:

void Print(){ cout<< "C"; }

};

int main()

{

A ob1;

B ob2;

C ob3;

A *obj;

obj = &ob1;

obj?>Print();

obj = &ob2;

obj?>Print();

obj = &ob3;

obj?>Print();

}
A . void Print(){ cout<<"A";}
B . virtual void Print(){ cout<<"A";}
C . virtual void Print(string s){ cout<<s;}
D . None of these

Answer: B

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments