首页 > 试题广场 >

其中"c.getDeclaredMethods"的作用是:

[单选题]
其中"c.getDeclaredMethods"的作用是:
import java.lang.reflect.Method;
public class DumpMethods{
public static void main(String[] args) {
try {
Class c=Class.forName(args[0]);
Method m[]=c.getDeclaredMethods();
for (int i = 0; i < m.length; i++) {
System.out.println(m[i].toString());
}
} catch (Throwable e) {
System.err.println(e);
}
}
}
  • 取得类的公有方法对象
  • 取得类的所有公有方法名称
  • 取得类的所有方法对象
  • 选项都不正确
getDeclaredMethod() 获取的是类自身声明的所有方法
发表于 2019-10-08 11:24:53 回复(0)
public Method[] getMethods()返回某个类的所有公用(public)方法包括其继承类的公用方法,包括它所实现接口的方法
public Method[] getDeclaredMethods()对象表示的类或接口声明的所有方法,包括公共、保护、默认(包)访问和私有方法,但不包括继承的方法。包括它所实现接口的方法
发表于 2018-12-21 17:59:55 回复(1)
public Method[] getMethods()
* Returns an array containing {@code Method} objects reflecting all the public methods of the class or interface represented by this {@code Class} object, including those declared by the class or interface and those inherited from superclasses and superinterfaces.
* 即返回调用对象的类或接口的所有共有方法,包括定义在它的父类或者父接口中的方法。
public Method[] getDeclaredMethods()
* Returns an array containing {@code Method} objects reflecting all the declared methods of the class or interface represented by this {@code Class} object, including public, protected, default (package) access, and private methods, but excluding inherited methods.
* 即返回调用对象的类或接口定义的所有方法,包括共有的、保护的、默认的和私有方法,但是不包括继承的方法。

编辑于 2021-03-28 11:06:42 回复(0)
c为啥不对呀
发表于 2020-02-05 23:36:02 回复(0)

是自身声明的类


发表于 2019-10-26 12:09:34 回复(0)
发表于 2019-10-23 21:50:47 回复(0)
...这道题到底怎么选择。。。
发表于 2019-10-21 19:37:56 回复(0)
不选c吗,不就是取得所有方法对象吗?
发表于 2019-10-05 20:36:26 回复(1)