Class c = Class.forName("T1"); Method[] m = c.getDeclaredMethods(); m[0].setAccessible(true); Object i = m[0].invoke(this, null); //这里调用私有方法时,参数不是父类对象也可以。 System.out.println(i);
Java Language Specification 3 [解决办法] 是继承了,但是没有权限访问 用反射就不一样了,因为执行了setAccessible(true),就可以访问了 [解决办法] 对啊,是继承,把继承来的私有函数公有化就可以用了. [解决办法] Does subclasses inherit private fields?
[解决办法] 按照java认证程序员考试指南上的说法是子类没有继承父类的私有成员。
"When a member is declared private, a subclass can't inherit it."
- <<Sun Certified Programmer for Java 5 Study Guide : SCJP Exam 310-055>> 英文版 第一章第三十页 [解决办法] 不会继承
补充30楼的: As the JLS states:http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.2
Members of a class that are declared private are not inherited by subclasses of that class. Only members of a class that are declared protected or public are inherited by subclasses declared in a package other than the one in which the class is declared