2014年5月22日星期四

Access permissions error

modified
I have two classes , inheritance relationship, I want to access the protected subclass inside the property of the parent class , but still can not access , error, I do not know what the reason is inside MyEclipse / then I wrote two simple test class test a little , or not,

package cn.test.testAccess;

public class TestAccess {
/ * public static void main (String [] args) {
T t = new T ();
t.j = 91;
t.k = 23;
t.kk = 54;

} * /

private int i = 9;
int j = 90;
protected int k = 92;
public int kk = 80;

}

package cn.test.testAccess1;

import cn.test.testAccess.TestAccess;

public class Test extends TestAccess {
public static void main (String [] args) {
TestAccess test = new TestAccess ();
test.kk = 60;
test.k = 20;
}

}

------ Solution ------------------------------------ --------
you obviously new is the parent class. .
public class Test extends TestAccess{
    public static void main(String[] args){
    TestAccess test = new TestAccess();
    test.kk = 60;
    test.k = 20;
}


this is the subclass. .
public class Test extends TestAccess{
    public static void main(String[] args){
    Test test = new Test();
    test.kk = 60;
    test.k = 20;
}

------ Solution ------------------------------------- -------

protected is a class , subclass, and the package can be seen , of course you can not visit
------ For reference only other bag ----- ----------------------------------
test.k error
------ For reference only ---------------------------------------
protected property such access is not to it !
The only public can now !
------ For reference only -------------------------------------- -
usually the fault of the program itself ;
------ For reference only -------------------------- -------------
  The reply was deleted administrator at 2014-05-21 20:25:58

------ For reference only ---------------------------------- -----
that references the parent class , I can not refer to the parent class member variables do
------ For reference only ---------------- -----------------------
have given you

没有评论:

发表评论