import
java.lang.reflect.Method;
public
class
GFG {
public
static
void
main(String[] args)
throws
NoSuchMethodException, SecurityException,
ClassNotFoundException
{
Method[] methods = GFGClass.
class
.getMethods();
Method method
= GFGClass.
class
.getMethod(
"add"
, String.
class
);
System.out.println(
"First Method object from array "
+
"create by getMethods():"
);
System.out.println(methods[
0
]);
System.out.println(
"Method object created by "
+
"getMethod():"
);
System.out.println(method);
if
(methods[
0
].equals(method)) {
System.out.println(
"Both Method objects"
+
" are equal"
);
}
else
{
System.out.println(
"Both Method objects"
+
" are not equal"
);
}
}
}
class
GFGClass {
private
String field1;
public
GFGClass() {}
public
String add(String field2)
{
return
this
.field1 + field2;
}
}