Created
December 7, 2012 21:37
-
-
Save MihailJP/4236740 to your computer and use it in GitHub Desktop.
You cannot override a class (static) constant (Java)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parent { | |
static final int Val = 1; | |
public int getval() { | |
return Val; | |
} | |
} | |
class Child extends Parent { | |
static final int Val = 2; | |
} | |
public class ConstTest1 { | |
public static void main(String[] args) { | |
Child instance = new Child(); | |
System.out.println(instance.getval()); // You'll see '1', expected '2'. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parent { | |
int Val() {return 1;} | |
public int getval() { | |
return Val(); | |
} | |
} | |
class Child extends Parent { | |
int Val() {return 2;} | |
} | |
public class ConstTest2 { | |
public static void main(String[] args) { | |
Child instance = new Child(); | |
System.out.println(instance.getval()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment