C++ Programming - OOPS Concepts - Discussion

Discussion :: OOPS Concepts - General Questions (Q.No.51)

51. 

Which one of the following options is correct?

[A]. Friend function can access public data members of the class.
[B]. Friend function can access protected data members of the class.
[C]. Friend function can access private data members of the class.
[D]. All of the above.

Answer: Option D

Explanation:

No answer description available for this question.

Ishu said: (Oct 1, 2012)  
Friend function can only access the private data members of a class. Is this correct?

Manoj Kumar Sahoo said: (Jul 31, 2013)  
Friend function can access all private, protected and public data members of a class. So option D is right.

Rajkumar said: (Sep 23, 2013)  
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);
}

Nilofer said: (Oct 3, 2013)  
Friend function can access private members of class.

Prisci said: (Oct 10, 2013)  
What is friend function?

Ghost In Oops said: (Oct 22, 2013)  
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: (Feb 23, 2017)  
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.

Hatos said: (Mar 2, 2018)  
Why do we need "friend"?

If a public function can be accessed from the outside?

Akshit Mittal said: (Nov 18, 2018)  
According to me, friend function can access private data of the class.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.