I can understand that static cannot be overridden by non-static.
Example:
Class A
{
static void m1()
{
Sysytem.out.print(" m1 in A ");
}
}
Class B extends A
{
void m1()
{
Sysytem.out.print(" m1 in A ");
}
}
Class
test {
public static void main(
String ar[])
{
A a = new B();
a.m1();// ----- (1)
}
}
Here (1) is resolved statically at compile time and m1() is never called for object b at run-time. I understand this.
Howver when I try the reverse, non-static overridden by static, why do I get compile time error. I would like a more detailed answer if someone has more knowledge as to how a.m1() is reolved in this case.
Class A
{
void m1()
{
Sysytem.out.print(" m1 in A ");
}
}
Class B extends A
{
static void m1()
{
Sysytem.out.print(" m1 in A ");
}
}
Class test
{
public static void main(String ar[])
{
A a = new B();
a.m1();// ----- (1)
}
}
Thanks in advance
Shre