Online Java Compiler By
JavaTpoint.com
import java.lang.reflect.*; public class ClassgetDeclaredMethodExample1 { public static void main(String[] args) { ClassgetDeclaredMethodExample1 obj = new ClassgetDeclaredMethodExample1(); Class class1 = obj.getClass(); try { // parameter type is null Method mthd = class1.getDeclaredMethod("showmethod", null); System.out.println("method 1 = " + mthd.toString()); // method Integer Class[] arg = new Class[1]; arg[0] = Integer.class; Method mthd1 = class1.getDeclaredMethod("showIntegermethod", arg); System.out.println("method 2 = " + mthd1.toString()); Class[] arg2 = new Class[1]; arg2[0] = float.class; Method mthd3 = class1.getDeclaredMethod("showFloatmethod", arg2); System.out.println("method 3 = " + mthd3.toString()); } catch(NoSuchMethodException e) { System.out.println(e.toString()); //print the exceptio object e } } private Integer showmethod() { return 1; } public void showIntegermethod(Integer i) { this.i = i; } public void showFloatmethod(float i) { this.f = f; } public int i = 88655; float f=3; }
Output