QUOTE(alpha02 @ 16 Aug, 2007 - 10:24 PM)

The "type 1" line shows A because the variable in declared in the same scope (the same code "block") as the System.out.println instruction....
Say what??? That makes no sense, the variable on which show is called is declared in main. For proof:
import java.lang.reflect.Field;
class A{
public static String MYTYPE = "A";
A(){}
String getType(){ return MYTYPE; }
void show(){
System.out.println("type A1a:"+MYTYPE);
System.out.println("type A1b:"+this.getType());
try{
Field f = this.getClass().getDeclaredField("MYTYPE");
System.out.println("typeA2 :"+f.get(this).toString());
}catch(Exception e){}
}
}
----
import java.lang.reflect.Field;
class B extends A{
public static String MYTYPE = "B";
B(){ super();}
String getType(){ return MYTYPE; }
void show(){
System.out.println("type B1a:"+MYTYPE);
System.out.println("type B1b:"+this.getType());
try{
Field f = this.getClass().getDeclaredField("MYTYPE");
System.out.println("typeB2 :"+f.get(this).toString());
}catch(Exception e){}
}
----
class C extends B{
public static String MYTYPE = "C";
C(){ super();}
public static void main(String[] argc){
A x = new C();
System.out.println("----------------------------------");
System.out.println("var x");
x.show();
B y = new C();
System.out.println("----------------------------------");
System.out.println("var y");
y.show();
}
}
[tzellers@localhost ~]$ java C
----------------------------------
var x
type B1a:B
type B1b:B
typeB2 :C
----------------------------------
var y
type B1a:B
type B1b:B
typeB2 :C
The one and only distinction between x and y is the cast type. It doesn't matter. What appears to matter is that a superclass method will not see the subclass's class (static) variables when run on a subclass object. I'm looking for a cogent explanation as to why that I can remember in an intelligent way - and hopefully one that will convince me that it *has* to be that way other than my growing unease that java's OO semantics are broken here.
-- TWZ