Is there a way to override class variables in Java?

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

    You cannot override variables in a class. You can override only methods. You should keep the variables private otherwise you can get a lot of problems.

提交回复
热议问题