FY-5-a Easy C++ program to design a class for single level inheritance

C++ program to design a class for single level inheritance

Design a class for single level inheritance using public and private type derivation.

Click here to get other OOP Practical

FYIT practical 5-a program for single level inheritance

#include
using namespace std;
class Base
{
int n, r;
public:
void get()
{
cout<<"Enter any number : ";
cin>>n;
}
void square()
{
r=n*n;
disp();
}
private:
void disp()
{
cout<<endl<<"Square of "<<n<<" is "<<r;
}
};
class Derived:public Base
{
int b;
};
int main()
{
Derived d;
d.get();
d.square();
return 0;
}

Output

single level inheritance itvoyagers

Check out more FYIT OOP Practical Program and other logic building programs in C++

We are aiming to explain all concepts of C++ and OOP in easiest terms as possible.
ITVoyagers-logo
ITVoyagers
Author

Leave a Comment