Logo 
Search:

C++ Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C++ ProgrammingRSS Feeds

What would be the output of the following code 2?

  Shared By: Dylan Evans    Date: Sep 16    Category: C++ Programming    Views: 623

Answer:

What would be the output of the following code?

#include<iostream.h>
#include<conio.h>
class A
{
public:
virtual void disp()
{
cout<<"This is from class A";
}
};

class B : public A
{
public:
void disp()
{
cout<<"This is from class B";
}
};
void main()
{
clrscr();
A *s;
s = new B();
s->disp();
}

Options

a) This is from class A
b) This is from class B
c) This is from class A This is from class B
d) None of the above


Answer : b) This is from class B

Share: 
 

Didn't find what you were looking for? Find more on What would be the output of the following code 2? Or get search suggestion and latest updates.


Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: