ProgrammingHardStatement-count style · Product-company MCQ pattern

How many of these statements about C++ friend functions are correct? (i) A friend function can access the private members of the class that declares it a friend. (ii) Friendship is inherited by classes derived from that class. (iii) Friendship is neither symmetric nor transitive. (iv) A friend function is called with the object.function() member syntax.

  1. A. Only one
  2. B. Only two
  3. C. Only three
  4. D. All four

Correct answer: B. Only two

(i) true. (ii) false: a friend of Base gets no access to what Derived adds. (iii) true: A being a friend of B does not make B a friend of A, nor friends of friends. (iv) false: it is not a member, so it is called like an ordinary function. So two.

More OOP with C++ and Java questions

Exams that ask this topic