Monday, June 11, 2012

Why interfaces cannot contain static methods where as they can contain static variables?

 1) Interface means, you can say that it is really incomplete....that is the reason, you can not create the instances...
2) In second point, the all methods in the interface are abstract method... Simply you can say, abstract methods are also the incomplete method.
3) And when the methods are incomplete, the class is also incomplete, so even for the abstract class which is partially incomplete, you can't create the object. Because it restricts the abstract methods to be called by object because they are abstract
4) And you know very well, that, static methods do not need any object to be created toget called of. So directly they can be called as <classname>.<methodname>.
5) Now think, when the method is abstract (may be in abstract class or interface), and it is incomplete, and you invoke that method, then, how it can be used when it is

incomplete???? So you can't use static. (When you use static with a method, you can call directly without creating an object). So you can't do it

No comments:

Post a Comment