VOOZH about

URL: https://www.geeksforgeeks.org/java/method-class-getparametercount-method-in-java/

⇱ Method Class | getParameterCount() method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Method Class | getParameterCount() method in Java

Last Updated : 11 Jul, 2025
The java.lang.reflect.Method.getParameterCount() method of Method class returns the number of parameters declared on a method Object. Syntax:
public int getParameterCount()
Return Value: This method returns number of formal parameters defined on this Method Object. Below programs illustrates getParameterCount() method of Method class: Example 1: Below Program returns No of Parameter for a specific Method given as Input.
Output:
Method Name: setManyValues
No of parameters:1
Example 2: Below Program return No of Parameters for all of Methods Defined in a class.
Output:
Method Name is DemoMethod1 and No of parameters = 1
Method Name is DemoMethod2 and No of parameters = 2
Method Name is DemoMethod3 and No of parameters = 0
Method Name is wait and No of parameters = 2
Method Name is wait and No of parameters = 1
Method Name is wait and No of parameters = 0
Method Name is equals and No of parameters = 1
Method Name is toString and No of parameters = 0
Method Name is hashCode and No of parameters = 0
Method Name is getClass and No of parameters = 0
Method Name is notify and No of parameters = 0
Method Name is notifyAll and No of parameters = 0
Explanation: Output of this program also showing results for method objects other than methods defined in class object like wait, equals, toString, hashCode, getClass, notify, notifyAll. These methods are inherited from superclass name Object of java.lang lang package by class object. Reference: https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Method.html#getParameterCount--
Comment