Create a class with a method that prints "This is parent class" and its subclass with another method that prints "This is child class".

Create a class with a method that prints "This is parent class" and its subclass with another method that prints "This is child class". Now, create an object for each of the class and call
1 - method of parent class by object of parent class
2 - method of child class by object of child class
3 - method of parent class by object of child class




Solution:



#include <iostream>

using namespace std;

class parent{

public:

parent()

{

cout<<"This is parent class."<<endl;

}

};

class child :public parent{

public:

child()

{

cout<<"This is child class."<<endl;

}

};


int main()

{

child c;

parent p;

}


Create a class with a method that prints "This is parent class" and its subclass with another method that prints "This is child class". Now, create an object for each of the class and call 1 - method of parent class by object of parent class 2 - method of child class by object of child class 3 - method of parent class by object of child class