#include <iostream>
using namespace std;
class A {
private:
int a;
protected:
int b;
public:
A(int m,int n)
{
a=m;
b=n;
}
// friend class declaration
friend class B;
};
class B {
public:
void display(A& t)
{
cout << "Sqaure of varible a = "
<< t.a*t.a << endl;
cout << "Cube of variable b = "
<< t.b*t.b;
}
};
int main()
{
cout<<"Friend class program "<<endl;
A ob1(2,3);
B ob2;
ob2.display(ob1);
return 0;
}
output:
Friend class program
Sqaure of varible a = 4
Cube of variable b = 9
0 Comments
Post a Comment