hi.. Because more the one class can implement the interface, and each of them can have it's own implementation which is not necessarily match those of others.Ex. if the MouseListener methodes were static, then you can have more than one listner throughout the application life time. Hope this help
An interface contains no implementations for its method declarations, the methods have to be provided by classes that implement the interface. The classes provide the implementation of the methods by overriding the methods specified in the interface. static methods cannot be overridden. So it is useless declaring a static method in an interface, because nothing can provide its implementation.
static methods cannot be overridden. So it is useless declaring a static method in an interface, because nothing can provide its implementation.
Is there any rule static Vs interface...just like rule abstract Vs final OR Java Developers just thinks that..there is no need of static methods in interface...and put that reststriction...interface methods can't have body.. and given a STRONG Defination for interface...
Is there any problem... if we have static methods too along with method declaration in interface... (of course if Java Developers allowed)..
Originally posted by Ramakrishna Nalla: Thank you hatim and Barry...
You may misunderstood my question...
Actually, Ramakrishna, you misunderstood the answer.
Static methods are bound to the class itself, not to the objects made of that class. In other words, If a static method is defined in another class, it's a different method, not an override. Which brings us to what Barry said:
Static methods cannot be overridden. So it is useless declaring a static method in an interface, because nothing can provide its implementation.
If you'd put a static method in an interface, you'd define a method that can not have a method body. As Barry so eloquently put it: that's a useless method.
think about it for a second there... Interface methods are meant to be implemented.
An interface defines a contract between itself and implementing classes, saying what they must implement and not how. But if you where allowed to have a static abstract method, what good would it be if its going to be part of the class and not any particular instance.
This would completly put polymorphism back in its box (and where would OO programing be without polymorphism?)
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD, SCEA/OCMJEA
Live life to an interface, not an implementation!
Joined: Apr 21, 2005
So much Thanks Barend..for correcting me...and also Marzo Kaahn... Once again thanks to Barry...
I just think like below code hence that question arises for me..