static method sparks error on overriding non-static method
I have some question concerning static overriding non-static methods. I have read up about "static" and have got to understand it as something that is attached to the class and all objects of the class can only refer and if not final, change the value, which affects the value of all the other objects.
The question I have is that if there is a scenario like the one below:
Why do we get a compilation Err at line 10? Why cant static methods override the other method.
1: class Test
3: void show()
5: System.out.println("non-static method in Test");
8: public class Q3 extends Test
10: static void show()
12: System.out.println("Overridden non-static method in Q3");
15: public static void main(String args)
17: Q3 a = new Q3();
static - non static override
On this page tou can see the possible overrides in Java: java.sun.com/docs/books/tutorial/java/IandI/override.html
As you can see it isn't possible to override static with non static, or override non static with static because one refers to the object and the other to the class.
the only solution is to make both method static or both non static