java+方法覆盖必须不减可见性,域却可以隐藏。

package com.cisco.learning;

public class Parent {

public int i=20;

public void test() {

}

public static void main(String[] args) {
//10
System.out.println(new Sun().i);
}

}

class Sun extends Parent{

int i=10;

/*//Cannot reduce the visibility of the inherited method from Parent
private void test() {

}*/

}
//总结: 实现或者继承时,覆盖或者实现的方法不能减少可见性,同时异常不能增多,但是域成员可以重新定义(可见性较少);

导出方法:只能发扬光大(提高可见性,减少异常),不能据为己有;

域: 可以被子类隐藏(我只让别人看我的行为不看资料)

只能这么记了。。

你可能感兴趣的:(java)