This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Abstract methods must be overridden by subclasses to provide implementation. Since private methods are not visible in subclasses abstract methods cannot be private. Similarly, since static methods cannot be overridden, they cannot be static either. Try out this code and see what the compiler says -
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Joined: Nov 05, 2000
Hai Ajith Kallambella Thanks for ur response. But is it true that Static methods must be overridden to be Static.They can't be overridden to be non static.
Need some response thanks
Joined: Mar 17, 2000
No. Static methods cannot be overridden at all. Here's why - Unlike instance methods which is associated with the objects of a particular class, static methods( and static variables ) are associated with the class itself. So, when a class is subclassed, if the superclass contains static entities( methods/variables ), they are not inherited in the subclass. You can only override something that is inherited and hence static entities cannot be overridden. What's more, static methods are resolved at compile time and (since they cannot be overridden, ) they do not exhibit polymorphism (aka runtime binding ). Often people get confused between overriding and redeclaration. Static methods can be redeclared in the subclass and when you do so, the new method shadows or hides the method in the superclass. Hope that helps, Ajith