Question: Extend the code of Figure 16.4 to print information about (a) Fields (b) Constructors (c) Nested classes (d) Implemented interfaces (e) Ancestor classes, and their
Extend the code of Figure 16.4 to print information about
(a) Fields
(b) Constructors
(c) Nested classes
(d) Implemented interfaces
(e) Ancestor classes, and their methods, fields, and constructors
(f) Exceptions thrown by methods
(g) Generic type parameters
Figure 16.4:

import static java.lang.System.out; public static void listMethods (String s) throws java.lang.ClassNotFoundException { Class c = Class.forName (s); for (Method m : c.getDeclaredMethods ()) { out.print (Modifier.toString (m.getModifiers ()) + " "); out .print (m.getReturnType ().getName () + " "); out.print (m.getName () + "("); // throws if class not found boolean first = true; for (Class p : m.getParameterTypes ()) { if (!first) out.print (", "); first = false; out.print (p.getName ()); out.println(") "); Sample output for listMethods ("java.lang.reflect.Accessible0bject"): public java.lang.annotation. Annotation getAnnotation (java.lang.Class) public boolean isAnnotationPresent (java.lang.Class) public [Ljava.lang.annotation. Annotation; getAnnotations () public [Ljava.lang.annotation. Annotation; getDeclaredAnnotations () public static void setAccessible( [Ljava.lang.reflect. Accessible0bject;, boolean) public void setAccessible (boolean) private static void setAccessible0(java.lang.reflect.Accessible0bject, boolean) public boolean isAccessible ()
Step by Step Solution
3.41 Rating (157 Votes )
There are 3 Steps involved in it
ANSWER import static javalangSystemout public static void listMethods String s throws javalangClassNotFoundException Class c ClassforNames throws if c... View full answer
Get step-by-step solutions from verified subject matter experts
