C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 51)
51.
Which one of the following options is correct?
Friend function can access public data members of the class.
Friend function can access protected data members of the class.
Friend function can access private data members of the class.
All of the above.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
9 comments Page 1 of 1.

Rajkumar said:   1 decade ago
Friend function can access protected and public members of both classes and it can also access private members by using object of that class.

class plus
{
private:float x,y;
public:plus(){x=0;y=0;}
plus(int i,int j)
{
x=i;y=j;
}
friend plus operator+(plus ob1,plus ob2);
void display()
{
cout<<"x and y"<<x<<y;
}
plus operator+(plus ob1,plus ob2)
{
plus temp;
temp.x=ob1.x+ob2.x;
temp.y=ob1.y+ob2.y;
return(temp);
}

Ghost in oops said:   1 decade ago
Friend function is one which is used to access the private data of a class for which it is defined. It can also used to access protected and public data of a class for which it is defined as a friend.

Renuka said:   9 years ago
Friend function is a non-member function, to access the data within a class as well as out side the class. It can also use private and public member of class.
(1)

MANOJ KUMAR SAHOO said:   1 decade ago
Friend function can access all private, protected and public data members of a class. So option D is right.

Ishu said:   1 decade ago
Friend function can only access the private data members of a class. Is this correct?

Hatos said:   8 years ago
Why do we need "friend"?

If a public function can be accessed from the outside?

Akshit mittal said:   7 years ago
According to me, friend function can access private data of the class.

Nilofer said:   1 decade ago
Friend function can access private members of class.

Prisci said:   1 decade ago
What is friend function?

Post your comments here:

Your comments will be displayed after verification.