class G1
{
static void method1()
{
System.out.println("method in super class");
}
}
class G2 extends G1
{
static void method1()
{
System.out.println("method in sub class");
}
}
public class CheckStatic
{
public static void main(
String[] q)
{
G1 w=new G2();----(1) //G2 w=new G2();---(2)
w.method1();
}
}
complation is succeed for the above code.
case (1):
if you are using superclass reference variable which is used to call method1 which shows the output as "method in super class".
case (2):
if you are using sub class reference variable then you will get ouput as "method in sub class".
so method execution is depends upon the reference variable which is used to call the method1.
but
in case of overriding if you mention line ---(1)
then we should get output as "method in sub class".
so,here static methods are not overriding.