SHARE
TWEET

inheritance of static fields

DulcetAirman Sep 7th, 2018 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top