Interviews6 answers
Why we can not provide access modifer while declaration interface ?
6 Answers
because they are all public by default
Ashish kandhowaPosted Feb 22, 2011, 8:59 PM EST
An interface describes a group of related functionality for a class or structure. They are automatically public and cannot include access modifiers. It is important to note that interfaces can hold properties, events, and indexers also. The interface is always public because it is a contract to be implemented and the implementer decides what access that particular function should have.
Felipe RamosPosted Feb 15, 2011, 5:56 AM EST
Because interfaces offer contracts. And the classes MUST implement the interface, so other modifiers could make the contract impossible because of the scope of the class (like internal modifier in different assemblies etc).
Marcelo BernartPosted Feb 11, 2011, 9:27 AM EST
Interface is the standard structure to be followed by the classes where class will implement the functionality and it includes only the declaration of methods,functions and properties.We cannot provide access modifier while declaration of interface bcoz interfaces are public by default and interfaces deals with public members only.
sarika jainPosted Feb 10, 2011, 7:52 PM EST
Hi Santosh,
Interface have by default Public access modifier so we need not to defined it .and interface take only public access modifier while declaring it.
shaikh shahbazPosted Feb 10, 2011, 7:52 PM EST
interface just like the abstract class in interface we only declare the methods not implement it
so for implementing the interface we need acess to all the methods of interface. hence by default the acess modifires for the interface is public
so for implementing the interface we need acess to all the methods of interface. hence by default the acess modifires for the interface is public
Deepak NehePosted Feb 10, 2011, 5:43 PM EST

