Java Class getMethods() Method21 Mar 2025 | 2 min read The getMethods() method of java Class class returns an array containing the method objects which represent all the public methods of the class or interface represented by a Class object, including those declared by the class or interface and inherited from superclasses and super interfaces. SyntaxParameterNA ReturnsThe array of Method objects ThrowsDoes not throw an exception Example 1Output: Methods = public void java.awt.Label.addNotify() public javax.accessibility.AccessibleContext java.awt.Label.getAccessibleContext() public int java.awt.Label.getAlignment() public java.lang.String java.awt.Label.getText() public synchronized void java.awt.Label.setAlignment(int) public void java.awt.Label.setText(java.lang.String) public void java.awt.Component.add(java.awt.PopupMenu) public void java.awt.Component.remove(java.awt.MenuComponent) public java.lang.String java.awt.Component.toString() public void java.awt.Component.update(java.awt.Graphics) public java.lang.String java.awt.Component.getName() public boolean java.awt.Component.contains(int,int) public boolean java.awt.Component.contains(java.awt.Point) public java.awt.Dimension java.awt.Component.size() public java.awt.Point java.awt.Component.getLocation(java.awt.Point) public java.awt.Point java.awt.Component.getLocation() public java.awt.Container java.awt.Component.getParent() Example 2Output: public static void ClassgetMethodsExample2.main(java.lang.String[]) public int ClassgetMethodsExample2.Calc(int) public void ClassgetMethodsExample2.Work() public static void ClassgetMethodsExample2.StaticMethod(java.lang.String) public final void java.lang.Object.wait() throws java.lang.InterruptedException public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException public boolean java.lang.Object.equals(java.lang.Object) public java.lang.String java.lang.Object.toString() public native int java.lang.Object.hashCode() public final native java.lang.Class java.lang.Object.getClass() Next TopicJava Class |
Java Class Method The method of java Class returns an array containing field objects representing all the accessible public fields of the class or interface represented by this Class object otherwise if no field is present then it returns an array of length 0. Syntax public...
2 min read
Java Class Method The method of java Class class returns the Type representing the direct superclass of the class, interface, primitive type or void represented by this Class. Syntax public Type getGenericSuperclass() Parameter Does not take the parameter. Returns the direct superclass of the class represented by this object. Throws GenericSignatureFormatError TypeNotPresentException...
2 min read
Java Class Method The method of java Class casts this Class object to represent a subclass of the class represented by the specified class object. It throws a ClassCastException if the cast is not valid otherwise it returns a reference to this(current) class object. Syntax public...
2 min read
Java Class Method The method of java Class class returns a Constructor object that reflects the public constructor of the class. Syntax public Constructor<T> getConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException Parameter parameterTypes - the parameter array. Returns Constructor object. Throws NoSuchMethodException , SecurityException Example 1 //import statements import java.lang.reflect.*; public class ClassgetConstructorExample1 { public...
2 min read
Java Class Method The method of java Class class returns annotations that are present on this element. If there are no annotations present on this element, then it returns an array of length 0. The caller of this method can modify the returned array. Syntax public...
2 min read
Java Class Method The method of java Class class gets the superclass of this class. If no superclass exists then null is returned. Syntax public Class<? super T> getSuperclass() Parameter NA Returns Immediate superclass of the class Throws NA Example 1 import java.lang.*; public class ClassgetSuperClassExample1 extends Object { public static void main(String...
1 min read
Java Class Method The method of java Class class returns true if the underlying class is an anonymous class. Syntax public boolean Parameter NA Returns true if this class Is an anonymous class. Throws NA Example 1 //import statements import java.lang.*; public class ClassisAnonymousClassExample1 { public static void main(String[] args) { ...
1 min read
Java Class Method The method of java Class class returns this element's annotation for the specified type if any annotation is directly present otherwise null. Syntax public <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationClass) Parameter annotationClass - the Class object corresponding to the annotation type Returns annotation for the specified annotation...
2 min read
Java Class Method The method of java Class class returns this element's annotation for the specified type if such an annotation is directly present, otherwise null. It ignores inherited annotations. Syntax public <A extends Annotation> A[] getDeclaredAnnotationsByType(Class<A> annotationClass) Parameter annotationClass - the Class object corresponding to the annotation...
2 min read
Java Class Method The method of java Class class returns true if this class is a synthetic class; returns false otherwise. Syntax public boolean Parameter No parameter is passed. Returns true if and only if this class is a synthetic class as defined by the Java Language Specification. Throws NA Example 1 import...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India