DulcetAirman icon

inheritance of static fields

DulcetAirman | PRO | 09/07/18 09:33:59 PM UTC | 0 ⭐ | 564 👁️ | Never ⏰ | []
Java |

750 B

|

None

|

0 👍

/

0 👎

package ch.claude_martin;
 
interface Colorable {
  int RED = 0xff0000, GREEN = 0x00ff00, BLUE = 0x0000ff;
}
 
interface Paintable extends Colorable {
  int MATTE = 0, GLOSSY = 1, RED = 0xDEAD;
}
 
abstract class AColorable implements Colorable, Paintable {
}
 
public class SomeClass extends AColorable implements Colorable, Paintable {
 
  public static void main(String[] args) {
    new SomeClass().sayHello();
  }
 
  private void sayHello() {
    System.out.println("hello world");
    System.out.println(this.MATTE); // this is not ambiguous, but the static field should be accessed in a static way
    System.out.println(this.RED); // this is ambiguous, does not compile
    System.out.println(Colorable.RED); // this is not ambiguous
  }
 
}

Comments