Answer Posted / nilesh more
Finally, remember that static methods can't be overridden!
This doesn't mean they can't be redefined in a subclass, but
redefining and overriding aren't the same thing.
Let's take a look at an example of a redefined (remember,
not overridden), staticmethod:
class Animal
{
static void doStuff()
{
System.out.print("a ");
}
}
class Dog extends Animal
{
static void dostuff()
{ // it's a redefinition,
// not an override
System.out.print("d ");
}
public static void main(String [] args)
{
Animal [] a = {new Animal(), new Dog(), new Animal()};
for(int x = 0; x < a.length; x++)
a[x].doStuff(); // invoke the static method
}
}
Running this code produces the output:
a a a
The above written material is from kathe Siera which clearly
says that "Static methods can't be overridden."
But you can only redefine them which is not as overriding.
For any further perfect explanation please refer kathe Ciera
book
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Can you give me a simple example of using the requiredif validator rule?
Is a class a subclass of itself?
What happens when a thread cannot acquire a lock on an object?
what is handle?
Can I import same package/class twice? Will the jvm load the package twice at runtime?
How task's priority is used in scheduling?
Is “abc” a primitive value?
What restrictions are placed on the location of a package statement within a source code file?
What method is invoked to cause an object to begin executing as a separate thread?
What is jboss?
Should synchronization primitives be used on bean methods?
What is the difference between static and non-static with examples?
Name three component subclasses that support painting?
How will you pass parameters in RMI? Why do you serialize?
Are we allowed to change the transaction isolation property in middle of a transaction?