Java:当我使用extends关键字实现多重继承时,在不同包的不同类中没有访问受保护的方法

Java:当我使用extends关键字实现多重继承时,在不同包的不同类中没有访问受保护的方法,java,Java,我有以下两门课: Test.java package com.test.app; public class Test { public int a=10; protected void testFunc() { // TODO Auto-generated method stub System.out.println("Test class--> testFunc"); } } 另一个是 主类 包com.test.main im

我有以下两门课: Test.java

package com.test.app;

public class Test {

    public int a=10;
    protected void testFunc() {
        // TODO Auto-generated method stub
        System.out.println("Test class--> testFunc");
    }
}
另一个是 主类 包com.test.main

import com.test.app.Test;


public class Main extends Test {


    public static void main(String[] argv) {

        System.out.println("Main Method");

        Main main =new Main();
        main.testFunc(); // No Error


        Test test = new Test();
        test.testFunc(); // Error

    }

}
类型测试中的test.testFunc()方法不可见

只有子类(如
Main
)和同一包中的类(
com.test.app
)可以访问
test#testFunc()
方法

这就是为什么要发表声明

main.testFunc();
编译很好(因为
Main
Test
的子类,并且允许调用
testFunc()


然而,这一声明

test.testFunc();
不编译,因为
Main
类所在的包不是
com.test.app
,而是
com.test.Main

更多信息:


问题是什么?是的,软件包就是这样工作的。这是一个功能。。。不是一个bug…我无法访问main method中的受保护方法。我认为链接将对您有更多帮助。是对你答案的一个很好的参考/证明:)是的,我同意你的答案,但这里我的问题是我从超类扩展而来,所以在这种情况下,受保护的方法应该在不同的包中可用??这样在上面的主类中可以得到测试类的特性,包括受保护的方法对吗!??但当我使用测试类的对象Test.testFunc()时,testFunc()在主类中不可见