Oracle Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: Written Test
I really wonder if Polymorphism is the correct answer. In the below code the parent pointer points to a derived object, but compilation error will be thrown when this parent pointer tries to access a function which is there only in Derived class object
#include <iostream>
using namespace std;
class B
{
public: virtual void fun() {cout<<"Base"<<endl;};
};
class D2:public B
{
public: virtual void fun() {cout<<"der2"<<endl;};
public: virtual void OnlyInDerived() {cout<<"fun1"<<endl;};
};
main()
{
D2 d;
B *b=&d;
b->OnlyInDerived();
}
I think its polymorphism. You will not worry about exact class if a base class ref/pointer holds base/derived class object
is there any reason why you have chosen abstraction?
Polymorphism
- seetha Devi January 05, 2012