Is there a way to override class variables in Java?

后端 未结 17 1107
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 09:49
class Dad
{
    protected static String me = \"dad\";

    public void printMe()
    {
        System.out.println(me);
    }
}

class Son extends Dad
{
    protected         


        
17条回答
  •  既然无缘
    2020-11-22 10:19

    This looks like a design flaw.

    Remove the static keyword and set the variable for example in the constructor. This way Son just sets the variable to a different value in his constructor.

提交回复
热议问题