转自: https://blog.csdn.net/qq_36443736/article/details/82890011
getMethod():获取自身能用所有的public公共方法。1.类本身的public 2.继承父类的public 3.实现接口的public
getDeclaredMethod():获取类自身声明的所有方法,包含public、protected和private方法。。
getMethod()获取继承父类的public方法举例:
public class Father { public Father() { System.out.println("调用了父类构造方法"); } public void fatherSay() { System.out.println("我是爸爸"); } } public class Son extends Father { public Son() { // TODO Auto-generated constructor stub System.out.println("调用了子类构造方法"); } public void sonSay() { System.out.println("我是儿子"); } public static void main(String[] args) { Son son=new Son(); son.fatherSay(); } }