Thursday 29 April 2021

Friend Class in C++

 #include<iostream.h>

#include<conio.h>

class A

{

int a, b;

void display()

{

cout<<"Display"<<endl;

}

public:

void display1()

{

cout<<"Display-1"<<endl;

}

friend class B;

};


class B

{

public:

void show()

{

cout<<"Show of B:"<<endl;

A ob;

ob.display();

ob.display1();

ob.a=5;

ob.b=10;

cout<<ob.a+ob.b<<endl;


}

};

main()

{

clrscr();

B ob;

ob.show();

getch();

return 0;

}

No comments:

Post a Comment