Hi
1. static methods can not be overidden they are only hidden so when you give the same signature of method in derived class as in the base class then that method is hidden only no
polymorphism takes place it is type of reference whoes method will be called compiler will not check to which class this reference is pointing to at runtime.
2. final methods cannot be overridden.
3. when the method is static and final it means that you cannot even give the same signature of the method in derived class as in base class.
In this example
class testrun
{
boolean tell;
static void foo() // No final is given
{
System.out.println("Hi inside base class");
}
}
class test2 extends testrun
{
boolean tell;
static void foo()
{ System.out.println("I am Amit");
}
public static void main(
String args[])
{
testrun t = new test2();
t.foo();
}
}
So output: Hi inside base class
and when you try to do something like this
import java.io.*;
class testrun
{
boolean tell;
final static void foo()
{
System.out.println("Hi inside base class");
}
}
class test2 extends testrun
{
boolean tell;
static void foo()
{ System.out.println("I am Amit");
}
public static void main(String args[])
{
testrun t = new test2();
t.foo();
}
}
the compiler will complain that final method can not be overridden.
Hope this will clear your doubts.
Regards
Rashi