package first;public class TestQ {
public int a ;
protected int b;
}
package second;
import first.TestQ;public class TestQ1 extends TestQ{
TestQ test = new TestQ();
int a1 = a;
int b1 = b;//int b1 = test.b;
}为什么注释中的代码(通过父类对象来访问父类的protected属性)不可以,而直接访问就可以?
public int a ;
protected int b;
}
package second;
import first.TestQ;public class TestQ1 extends TestQ{
TestQ test = new TestQ();
int a1 = a;
int b1 = b;//int b1 = test.b;
}为什么注释中的代码(通过父类对象来访问父类的protected属性)不可以,而直接访问就可以?
{
protected int i = 9;
public static void main(String[] args)
{
Test1 t1 = new Test1();
System.out.println(t1.j);
}
}
class Test1
{
protected int j = 1;
}
所以还是满足:
Protected声明的变量不同包的类对象不能访问的
~~~