This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I have a question that concerns overriding. When you override a method it can not be more restrictive or throw any checked exceptions of classes that are not possible for the original method. Correct me if I am wrong, but you can override a non-static method to be static? 1. Am I correct? 2. My question is if you can override a static method to be non-static? 3. How does this affect overloading in terms of static and non-static methods? Kind Regards Fred !(SCJP2)
The overriding method can have a different throws clause as long as it doesn't declare any types not declared by the throws clause in the overridden method. Also, the access specifier for the overriding method can allow more access than the overridden method, but not less. About your question 2: a subclass cannot override methods that are declared static in the superclass. In other words, a subclass cannot override a class method. A subclass can 'hide' a static method in the superclass by declaring a static method in the subclass with the same signature as the static method in the superclass.
u can't override a static method to be non-static neither can u override a non-static to be static u can only redeclare a static method to be the same as the one in the superclass just like bazan said.it sometimes look like u are overriding a static method with a static method but u are only redeclaring. in overloading it is a different ballgame u can read more in www.jchq.net\tutorial or java sun's tutorials [ June 18, 2002: Message edited by: khella smith ]
A compile-time error occurs if an instance method overrides a static method.
If a class declares a static method, then the declaration of that method is said to hide any and all methods with the same signature in the superclasses and superinterfaces of the class that would otherwise be accessible to code in the class. A compile-time error occurs if a static method hides an instance method.
"JavaRanch, where the deer and the Certified play" - David O'Meara