I found this piece of information about overriding in the
java's sun tutorial which you might find useful:
"A subclass cannot override methods that are declared final in the superclass (by definition, final methods cannot be overridden). If you attempt to override a final method, the compiler displays an error message similar to the following and refuses to compile the program:
FinalTest.java:7: Final methods can't be overridden.
Method void iamfinal() is final in class ClassWithFinalMethod.
void iamfinal() {
^
1 error
Also, a subclass cannot override methods that are declared static in the superclass. In other words, a subclass cannot override a class method. A subclass can hide a static method in the superclass by declaring a static method in the subclass with the same signature as the static method in the superclass. "
When you print A.j the output will be 2 as j is a static variable and it belongs to the class.Every instance of class A share the same value of j.You set a.j=2 for an instance 'a' of class A.Hence j is set to 2 for all instances of class A.A static variable can also be invoked without an instance of the class i.e directly using the class name.Hence invoking a.j or A.j gives you the same result i.e 2.
Hope this helps.