inheriting statics

Neil Mix nmix at pandora.com
Tue Jan 9 08:32:29 PST 2007


> In other words, statics are inherited and can be redefined,  
> although they are statically resolved, so they have shadowing  
> semantics (like instance fields) rather than overriding.

Yes, but it still means that you can't emulate Java's behavior  
without breaking backward compatibility. Thus, if I'm understanding  
correctly, no matter how you slice it one of Peter's list of 3  
advantages won't hold.

For example, modifying your Java example slightly:

public class C1 {
	static int foo = 10;
	void C1() {
	}
	
	void print() {
		System.out.println(this.foo);
	}
}

class C2 extends C1 {
	static int foo = 1000;
}

public class Main {
     public static void main(String[] args) {
         C2 x = new C2();
         x.print();
     }
}

Which will print 10.



More information about the Es4-discuss mailing list