Source Code : Get the methods of a class object

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Get the methods of a class object

        
import java.lang.reflect.Method;

class GetMethods {
  public int add(int numberA, int numberB) {
    return numberA + numberB;
  }

  protected int multiply(int numberA, int numberB) {
    return numberA * numberB;
  }

  private double div(int numberA, int numberB) {
    return numberA / numberB;
  }
}

public class Main {
  public static void main(String[] args) throws Exception {
    GetMethods object = new GetMethods();
    Class clazz = object.getClass();

    Method[] methods = clazz.getDeclaredMethods();
    for (Method method : methods) {
      System.out.println("Method name        = " + method.getName());
      System.out.println("Method return type = " + method.getReturnType().getName());

      Class[] paramTypes = method.getParameterTypes();
      for (Class c : paramTypes) {
        System.out.println("Param type         = " + c.getName());
      }
    }
 }

}

   
    
    
    
    
    
    
    
  

Thank with us