Get all methods including the inherited method. Using the getMethods(), we can only access public methods. : Super Class « Reflection « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » Reflection » Super Class 
7.13.3.Get all methods including the inherited method. Using the getMethods(), we can only access public methods.Previous/Next
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[] argsthrows Exception {
    GetMethods object = new GetMethods();
    Class clazz = object.getClass();

    Method[] methods = clazz.getMethods();
    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());
      }
    }
    Method method = clazz.getMethod("add"new Class[] { int.class, int.class });
    System.out.println("Method name: " + method.getName());
  }
}
7.13.Super Class
7.13.1.Get super class of an object
7.13.2.Superclass of Object is null
7.13.3.Get all methods including the inherited method. Using the getMethods(), we can only access public methods.
7.13.4.The superclass of primitive types is always null
7.13.5.Getting the Superclass of an Object
7.13.6.Is Inheritable
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.