create Father class and Son class derived from that Father class. Has same member function activity. Father activity is go to office. Student Task is goto Schoo.
1. Wap to display the only Son task without display the father activity by using virtual function.
2. Wap to display only Father activity without display son activity using virtual function.
3. Wap to display Both father and son activity by using virtual function.
#include <iostream>
#include <string>
using namespace std;
class Father
{
public:
void activity()
{
cout<<"Father activity is to go office"<<endl;
}
} ;
class Student: public Father
{
public:
void activity()
{
cout<<"The student task is go to school"<<endl;
}
void both()
{
cout<<"Father activity is to go office while ";
cout<<"The student task is go to school"<<endl;
}
};
int main()
{
Father *father = new Father;
Student *student = new Student;
student->activity();// display the only Son task without display the father activity
father->activity(); // display only Father activity without display son activity
student->both(); // display Both father and son activity by using virtual function
return 0;
}
Comments
Leave a comment