Java Class getDeclaredMethod() Method

21 Mar 2025 | 2 min read

The getDeclaredMethod() method of java Class class returns a method object representing the specified method declared inside the class or the interface of this class.

Syntax

Parameter

name - the name of the method

parameterTypes - the parameter array

Returns

Method object.

Throws

NoSuchMethodException , SecurityException

Example 1

Output:

 method 1 = private java.lang.Integer ClassgetDeclaredMethodExample1.showmethod() method 2 = public void ClassgetDeclaredMethodExample1.showIntegermethod(java.lang.Integer) method 3 = public void ClassgetDeclaredMethodExample1.showFloatmethod(float) 

Example 2

Output:

 private void ClassgetDeclaredMethodExample2$Sample1.Method1() public void ClassgetDeclaredMethodExample2$Sample1.Methodint(int) 
 
Next TopicJava Class