Class-Friendship via Interface

light111Class-Friendship via Interface

When one class wants to access the private method/attribute of another class, it is not generally possible but possible via a CLASS Friendship.


This is the usual class friendship that allows access to the private methods/attributes.




This friendship principle is possible via the interface also. The first class grants friendship to the interface and other class(es) if implement(s) this interface then it gets the permission to access the private methods/attributes. Below is the example:-





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s