Hi sc,
The
declared type 'B' is used to access variables. Value of 'x' in class 'B' is '10'.
There is no method 'm1()' in the actual type 'A' so the superclass is searched. 'm1()' in 'A' set 'x' to '20'. 'x.x' again uses the declared type 'B' to access the instance variable 'x' and '20' is output.
The method 'm1(int x)' is declared in the actual type 'A' so it is used. The method itself sets 'super.x' or 'B.x' to the value of the parameter variable 'x', '30'. Again, 'x.x' in the print refers to the declared type of class 'B'. The value of 'x' in 'B' is '30'.
The cast '((A)x)' is redundant ... 'x' has an actual type of 'A' and as mentioned above, the method 'm1(int x)' is declared in 'A' and references the superclass variable 'x'; so output is again '30'.
See
JLS §15.11 Field Access Expressions and
JLS §15.12 Method Invocation Expressions Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform