try {
A a = new A();
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 A {
public void a1() {
}
public void a2() {
}
protected void a3() {
}
private void a4() {
}
}
Here is the output from this program:
Public Methods:
a1
a2
836 Part II: The Java Library
Method Description
static boolean isAbstract(intval) Returnstrueifvalhas theabstractflag set andfalseother wise.
static boolean isFinal(intval) Returnstrueifvalhas thefinalflag set andfalseother wise.
static boolean isInter face(intval) Returnstrueifvalhas theinterfaceflag set andfalseother wise.
static boolean isNative(intval) Returnstrueifvalhas thenativeflag set andfalseother wise.
static boolean isPrivate(intval) Returnstrueifvalhas theprivateflag set andfalseother wise.
static boolean isProtected(intval) Returnstrueifvalhas theprotectedflag set andfalseother wise.
static boolean isPublic(intval) Returnstrueifvalhas thepublicflag set andfalseother wise.
static boolean isStatic(intval) Returnstrueifvalhas thestaticflag set andfalseother wise.
static boolean isStrict(intval) Returnstrueifvalhas thestrictflag set andfalseother wise.
static boolean isSynchronized(intval) Returnstrueifvalhas thesynchronizedflag set andfalseother wise.
static boolean isTransient(intval) Returnstrueifvalhas thetransientflag set andfalseother wise.
static boolean isVolatile(intval) Returnstrueifvalhas thevolatileflag set andfalseother wise.
TABLE 27-5 Methods Defined byModifierThat Determine Modifiers