Is there a way to override class variables in Java?

后端 未结 17 1064
没有蜡笔的小新
没有蜡笔的小新 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:23

    Yes, just override the printMe() method:

    class Son extends Dad {
            public static final String me = "son";
    
            @Override
            public void printMe() {
                    System.out.println(me);
            }
    }
    

提交回复
热议问题