#include<iostream>
using namespace std;
class Base{
protected:
int x=5;
public:
void display (){
cout<<"x = "<<x<<endl;
}
};
class Derived:public Base{
public:
int getFactorial(int a){
int fact=1;
for(int i=1;i<=a;i++){
fact=fact*i;
}
return fact;
}
void display (){
cout<<"Factorial of "<<x<<" is "<<
getFactorial (x);
}
};
int main()
{
Base b;
b.display();
Derived d;
d.display();
return 0;
}
Comments
Leave a comment