小编aro*_*aks的帖子

How to hide a static variable in Java

I have three classes with same methods and only constants are different. So what I wanted is to create one base class, which contains all the methods and to add three child classes which contain only constant variables. It looks like it is not possible to do so because of the dynamic binding. Please look at the example:

public class Parent {
    static String MY_CONSTANT = "bla bla";
    public void printSomething() {
        System.out.println(MY_CONSTANT);
    }
}

public class Child extends Parent …
Run Code Online (Sandbox Code Playgroud)

java inheritance binding

5
推荐指数
1
解决办法
1309
查看次数

标签 统计

binding ×1

inheritance ×1

java ×1