Question discussion

Which of the following statements about a friend function of a class in C++ is correct?

2520Medium DSSSB TGT Computer Science 0 replies 1 views
0

Which of the following statements about a friend function of a class in C++ is correct?

  • AIt is a member function and can be called only through an object of the class
  • BIt is inherited by every derived class automatically
  • CIt can access only the public members of the class
  • DIt is not a member of the class, but it can access the private and protected members of the class
Correct answer: D

Explanation

A friend function is declared inside the class with the keyword friend but defined outside it; it is not a member, yet it can access the private and protected members, and friendship is not inherited.

Discussion 0

Nobody has replied yet. Start the discussion!