Advertisement
DulcetAirman

inheritance of static fields

Sep 7th, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. package ch.claude_martin;
  2.  
  3. interface Colorable {
  4.   int RED = 0xff0000, GREEN = 0x00ff00, BLUE = 0x0000ff;
  5. }
  6.  
  7. interface Paintable extends Colorable {
  8.   int MATTE = 0, GLOSSY = 1, RED = 0xDEAD;
  9. }
  10.  
  11. abstract class AColorable implements Colorable, Paintable {
  12. }
  13.  
  14. public class SomeClass extends AColorable implements Colorable, Paintable {
  15.  
  16.   public static void main(String[] args) {
  17.     new SomeClass().sayHello();
  18.   }
  19.  
  20.   private void sayHello() {
  21.     System.out.println("hello world");
  22.     System.out.println(this.MATTE); // this is not ambiguous, but the static field should be accessed in a static way
  23.     System.out.println(this.RED); // this is ambiguous, does not compile
  24.     System.out.println(Colorable.RED); // this is not ambiguous
  25.   }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement