如题这个答案正确吗?
package com; public class TestParent { protected String protectedStr="protected"; String defaultStr="default"; private void method() { } void abm(){ } protected void proabc(){ } }
package com; public class TestSon extends TestParent{ private void test(){ } }
package com; class Main { static public void main(String[] args) { TestParent parent = new TestParent(); TestSon son = new TestSon(); parent.abm();//default method son.abm();//default method System.out.println(parent.protectedStr); System.out.println(parent.defaultStr); // ------------- parent.proabc(); //protected method son.proabc(); //protected method System.out.println(son.protectedStr); System.out.println(son.defaultStr); } }
作用域 | 当前类 | 当前包 | 子孙类 | 其他包 |
---|---|---|---|---|
public | √ | √ | √ | √ |
protected | √ | √ | √ | × |
friendly | √ | √ | × | × |
private | √ | × | × | × |
不写默认就是 friendly.
选 C 没毛病