Class: getDeclaredMethods() : Class « java.lang « Java by API






Class: getDeclaredMethods()

   
/*
 * Output:
Public Methods:
 a1
 a2
 * */

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class MainClass {
  public static void main(String args[]) {
    try {
      MyClass a = new MyClass();
      Class c = a.getClass();
      System.out.println("Public Methods:");
      Method methods[] = c.getDeclaredMethods();
      for (int i = 0; i < methods.length; i++) {
        int modifiers = methods[i].getModifiers();
        if (Modifier.isPublic(modifiers)) {
          System.out.println(" " + methods[i].getName());
        }
      }
    } catch (Exception e) {
      System.out.println("Exception: " + e);
    }
  }
}

class MyClass {
  public void a1() {
  }

  public void a2() {
  }

  protected void a3() {
  }

  private void a4() {
  }
}

           
         
    
    
  








Related examples in the same category

1.Class: forName(String classDec)
2.Class: Annotation[] getAnnotations()
3.Class: getCanonicalName()
4.Class: getClasses()
5.Class: getComponentType()
6.Class: getConstructors()
7.Class: getConstructor(Class...)
8.Class: getDeclaringClass()
9.Class: getDeclaredConstructors()
10.Class: getDeclaredFields()
11.Class: getDeclaredMethod(String name, Class... parameterTypes)
12.Class: getEnumConstants()
13.Class: getFields()
14.Class: getGenericInterfaces()
15.Class: getGenericSuperclass()
16.Class: getInterfaces()
17.Class: Method getMethod(String name, Class... parameterTypes)
18.Class: getMethods()
19.Class: getModifiers()
20.Class: getName()
21.Class: getPackage()
22.Class: getProtectionDomain()
23.Class: getResource(String name) (absolute from the classpath)
24.Class: getResource(String name) (relative to the class location)
25.Class: getResourceAsStream(String name)
26.Class: getSuperclass()
27.Class: getTypeParameters()
28.Class: isArray()
29.Class: isAssignableFrom(Class cls)
30.Class: isEnum()
31.Class: isInstance(Object obj)
32.Class: isInterface()
33.Class: newInstance()