- An interface contains only abstract methods i.e., methods without body.
- The interface contains only declaration for its members. We can not have any implementation code in the interface.
- An interface is a reference type(cannot be instantiated directly) and it contains only abstract members.
- Interfaces can be methods, properties, events, indexers, or any combination of those four member types
- All interface methods must be override.That means, interfaces are inheritable.
- Interfaces members are automatically public, and they cannot include any access modifiers.
- An interface cannot contain constants, fields, operators, instance constructors, destructors, or types. It cannot contain static members.
- Interfaces are allowed to extend other interfaces, but sub interface cannot define the methods declared in the parent interface, as sub interface is still interface and not class.
- Each variable declared in interface must be assigned a constant value.
- Multiple interfaces can be implemented with a class, thus gaining functionality one can't obtain with an abstract class.
- A class or struct can implement more than one interface.
- An interface itself can inherit from multiple interfaces.
- Syntax:
- public Interface <interface_name>
- For e.g.,
public interface Iclass { void method_name { };//we cann't have implementation } public class demoClass: Iclass { //implementation code }
Answer: They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it's public by default.
0 comments :
Post a Comment