Object Oriented Programming - Old Questions
Question Answer Details
4. "Concept of friend in against the philosophy of Object Oriented Programming". Explain.
Answer
AI Generated Answer
AI is thinking...
Official Answer
A friend function is a function that can access private members of a class even though it is not a member of that class.
A class can also be declared as friend of some other class. When a class ABC declares another class XYZ as its friend, then friend class XYZ can access to all data and function members of class ABC.
The philosophy of object oriented programming is that we can't access private members of a class from outside the class. But in C++, we can access private members of a class even from non-member function using concept of friend function and friend class. So, it is against the philosophy of Object Oriented Programming.