Tuesday, November 29, 2011

Why we can not override static method?

We can not override final method by definition, but we can override static method.:We CaNNOT override a static method. See a static method has nothing to do with the instance of the class. So when u r using a static method using .(dot) it actually subsitutes the class name. Inheritance is a concept based on instances. So when overriding u r actually redefining the method. Consider the example which will made ur concept more clear::I think one can override static method.:static method means one per class not one per instance.Overridding is done based on the type of object, and static methods are attached to a class:Static methods can be hidden. It cannot be overriden:Java does not encourage overriding the static method. Because static methods can be accessed directly from class with .(dot) operator. Hence class containing static methods does not required to create an instance to access its members.If u r using static methods just it represents the class name.Hence u cannot override static methods.:Static methods are not appeared in sub classes.we can&
Category:Java Interview Questions

No comments:

Post a Comment