tags:

views:

274

answers:

2

How can an access specifier to the member of interface be specified?

We can use interface as in two ways

  1. Inheritance ( IsA relation )
  2. Containment in another class (Has A relation).

In this way of implementation

protected access specifier is applied only to the events which are in inheritance relationship (IsA).

public access specifier is applied to the properties which are generally used as Has A relation (containment).

thz.. dinesh..

+4  A: 

All interface members are automatically public.

If inheritance and protected members are your goal, inherit from a base class instead. If composition is your goal, use interfaces.

Ian Nelson
You can have internal interfaces, which members are then also internal. :)
Frans Bouma
+2  A: 

Interface members have the same access operator as the interface they're in, that's the point of having an interface. Otherwise you'd have a public interface IFoo, which has an internal member Bar, which would be problematic if code wants to program against IFoo: it can't always access Bar, although it can use IFoo: the type implementing IFoo apparently doesn't implement Bar at that point.

So if you want to have some elements internal for example, use an internal interface for those members.

Frans Bouma