程序代码如下:
import java.lang.reflect.Method;
class AB{
protected String name;
protected String id;
}
public class MethodDemo5 extends AB{
void show(){}
public void say(){}
private int age;
public char c;
private boolean b;
public static void main(String[] args) throws Exception {
Class<MethodDemo5> c = MethodDemo5.class;
//获取所有的(包含父类的方法)public修饰的方法
Method[] m = c.getMethods();
for (Method method : m) {
System.out.println(method);
}
}
}
运行结果是:
public final void java.lang.Object.wait() throws java.lang.InterruptedException
public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
public boolean java.lang.Object.equals(java.lang.Object)
public java.lang.String java.lang.Object.toString()
public native int java.lang.Object.hashCode()
public final native java.lang.Class java.lang.Object.getClass()
public final native void java.lang.Object.notify()
public final native void java.lang.Object.notifyAll()
问题:MethodDemo5类只有两个pubilc方法main()和say(),为什么还会打印这么多public方法?看了好久还是不懂,各位求解答!!
|
|