Forums Register Login

Why methods in an interface cannot be static?

+Pie Number of slices to send: Send
All methods in an interface are implicitly public, abstract, and never static. Why methods in an interface cannot be static?
+Pie Number of slices to send: Send
Static methods are NEVER overridden. Instead, if you define a static method with the same name, return type and parameters as is defined in a superclass, you will hide that method.

Because static methods cannot be overridden, they need to have an implementation. But interfaces do not allow implementation of methods.

If an interface would allow static methods, this would lead to a situation similar to a final abstract method - the method is abstract, but it can never be implemented.
+Pie Number of slices to send: Send
Thanks a lot Rob Prime,You explained the things in a nice simple way....
Once again thanks
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 825 times.
Similar Threads
Static methods in an interface
Java Basics
Why cannot interface methods be static
interfaces
Static Methods in an Interface
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:24:48.