Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why the interface cannot have static member method [duplicate]

Tags:

c#

.net

Possible Duplicate:
Why shouldn't C#(or .NET) allow us to put a static/shared method inside an interface?

Why we cannot define static method inside interface?

like image 668
user496949 Avatar asked Jan 20 '11 10:01

user496949


People also ask

Why interface Cannot have static methods?

All methods in an interface are explicitly abstract and hence you cannot define them as static because static methods cannot be abstract.

Can we have static method in an interface?

Static methods in an interface since java8Since Java8 you can have static methods in an interface (with body). You need to call them using the name of the interface, just like static methods of a class.

Why static methods are not allowed in interface C#?

Because interfaces are in inheritance structure, and static methods don't inherit well.

Why interface has static and default methods?

Default methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older versions of those interfaces. A static method is a method that is associated with the class in which it is defined rather than with any object.


1 Answers

From the top search result in Google:

Because an interface is a "contract" or an agreement between the consumer (caller) and the provider (callee). An interface describes what and how the calle will provide functionality. There is no need for static members provided by a third party. Static members cannot be overridden by a provider so they do not belong in an interface.

Stefan Rusek

08 February 2006

like image 132
Massif Avatar answered Oct 22 '22 06:10

Massif