Difficulty: Easy
Correct Answer: Friend keyword can be used on main().
Explanation:
Introduction / Context:
The friend declaration in C++ grants access to private and protected members to specified functions or classes. It is a powerful but narrow tool: you can friend a function or a class, and you can place the friend declaration in any access section (public, protected, or private) without changing its effect. This item asks you to spot the statement that mischaracterizes friendship.
Given Data / Assumptions:
Concept / Approach:
Options A, B, and C all reflect valid uses: you may friend another class, and you may friend a specific function; the declaration can appear under public or private. Option D suggests “using friend on main()” which is, at best, ill-formed or meaningless in practical C++ design: the entry point requires a unique global signature; granting it friendship provides no sensible encapsulation mechanism and is not a recognized or advisable construct for access control questions like this. Therefore D is the incorrect statement in the intended sense of the question bank.
Step-by-Step Solution:
Verification / Alternative check:
Practical codebases never rely on granting friendship to main(). Try to “friend main” to gain special access and note it brings no coherent advantage; compilers or style rules will reject this pattern.
Why Other Options Are Wrong (i.e., not the incorrect statement):
A: Legal and common for tight class collaboration.
B/C: Friend declarations are unaffected by the access section where they appear.
Common Pitfalls:
Final Answer:
Friend keyword can be used on main().
Discussion & Comments