What is the use of friend function?

Answer Posted / damodar narayan

Visibility

The visibility of a property or method can be defined by prefixing the declaration with the keywords public, protected or private. Class members declared public can be accessed everywhere. Members declared protected can be accessed only within the class itself and by inherited and parent classes. Members declared as private may only be accessed by the class that defines the member.

The policy is if you are not a member, you can’t get it. But there is a certain situation wherein you need to share your private or protected data with nonmembers. ‘Friends’ come here as a rescue.

A friend function is a non-member function that grants access to class’s private and protected members.

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

can we swap two different string using php for example:-- before swapping:-- 1 string :-hello friend, 2 string :-my dear, after swapping that strings will be: 1.hello dear, 2.my friend.

3062


Explain preg_Match and preg_replace?

543


What are the difference between echo and print?

528


How many open modes available when a file open in PHP?

647


How to track no of user logged in?

623






Describe which programming language does php parallel to?

466


How to access a Static Member of a Class in PHP?

509


Tell me how to find current date and time?

537


What are arguments in php?

556


How to delete an element from an array?

552


What is the difference between require and include in php?

504


What is factory pattern in php?

488


What is php glob?

561


How to convert a json string to an array in php?

548


What are the benefits of using php and mysql?

502