xxxxxxxxxx
// CPP program to illustrate
// calling virtual methods in
// constructor/destructor
#include<iostream>
using namespace std;
class dog
{
public:
dog() //1
{
cout<< "Constructor called" <<endl;
bark() ;//2
}
~dog()//6
{
bark();//6
}
virtual void bark()//2,6
{
cout<< "Virtual method called" <<endl;
}
void seeCat()//4
{
bark();
}
};
class Yellowdog : public dog
{
public:
Yellowdog()//3
{
cout<< "Derived class Constructor called" <<endl;
}
void bark//5
{
cout<< "Derived class Virtual method called" <<endl;
}
};
int main()
{
Yellowdog d;
d.seeCat();
}
/*
Constructor called
Virtual method called
Derived class Constructor called
Derived class Virtual method called
Virtual method called
*/