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.
- A. Only one
- B. Only two
- C. Only three
- 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
- Interfaces A and B both declare default void hello(). What happens with class C implements A, B { } ?
- How many of these are correct in Java (8 or later)? (i) An abstract class can have a constructor. (ii) An interface can declare instance…
- What is printed? java // static methods of the main class: static void f() { try { System.out.print("1"); throw new…
- What is printed? java String s1 = "Java"; String s2 = "Ja" + "va"; String part = "Ja"; String s3 = part + "va"; System.out.print((s1 ==…
- What is printed? java class P { private void f() { System.out.print("P"); } void g() { f(); } } class C extends P { void f() {…
- What is printed? java class Animal { String speak() { return "animal"; } } class Dog extends Animal { String speak() { return "dog"; } }…