Method Signatures - AP Computer Science A

  1. What determines the method to execute among overloaded methods?
    Parameter list matching. Compiler matches arguments to parameter types and count.
  2. In 'float calculate(double x)', what is the return type?
    float. The data type returned when method execution completes.
  3. Identify the components of a method signature.
    Method name and parameter list. These uniquely identify how to call the method.
  4. What distinguishes overloaded methods in Java?
    Different parameter lists. Same name but different parameters allows multiple versions.
  5. In 'double getValue()', what is the return type?
    double. The data type this method produces when called.
  6. Identify the method signature: 'void compute(int a, double b)'.
    compute(int, double). Return type and access modifier are excluded from signature.
  7. What is the return type in the signature: 'boolean check(int x)'?
    boolean. Indicates the method returns a boolean value.
  8. How does Java distinguish between two overloaded methods?
    By their parameter lists. Return type alone cannot differentiate overloaded methods.
  9. In 'char getChar()', what is the method's return type?
    char. The data type the method will return when executed.
  10. Find the error in 'void method(int x, int x)'.
    Duplicate parameter names. Parameter names must be unique within the method scope.
  11. Find the error in the signature: 'int calculate(double x, double x)'.
    Parameter names must be unique. Each parameter needs a distinct identifier within the method.
  12. How many parameters are in 'void process(int a, float b, String c)'?
    Three parameters. Counts each comma-separated parameter in the list.
  13. What is the method name in 'boolean isValid(int a, int b)'?
    isValid. The identifier that appears before the parameter list.
  14. Identify the method name in the signature 'void draw()'.
    draw. The identifier used to invoke this method.
  15. Given the signature 'int add(int a, int b)', how many parameters are there?
    Two parameters. Counts the comma-separated parameters in parentheses.
  16. Which part of the method signature indicates its name?
    The method name itself. The identifier used to call the method.
  17. In 'void transform(int x)', what is the parameter type?
    int. The data type of the single parameter variable.
  18. Given 'void log()', identify a valid overloaded method.
    void log(String message). Adding parameters creates a different method signature.
  19. In the method signature 'void test()', what is the return type?
    void. Indicates no value is returned by this method.
  20. What does the parameter list in a method signature specify?
    Types and number of parameters. Determines what arguments can be passed to the method.
  21. State the rule for method overloading.
    Methods must differ in parameter types or number. Enables multiple methods with same name but different usage.
  22. What is the parameter type in 'String format(String pattern)'?
    String. The data type of the method's single parameter.
  23. Identify the method signature: 'public int compute(float num)'.
    compute(float). Access modifiers and return type are not part of signature.
  24. What does a void return type indicate in a method signature?
    Method returns no value. Indicates the method produces no output value.
  25. What is the parameter list in 'void setValues(int a, float b)'?
    int, float. The types of data the method accepts as input.
  26. Which method signature is a valid overload of 'void execute()'?
    void execute(int). Different parameter list makes this a valid overload.
  27. What is the effect of changing the parameter type in a signature?
    Creates an overloaded method. New signature allows method overloading to occur.
  28. Identify the error: 'double sum(int a, int a)'.
    Duplicate parameter names. Parameters must have unique names within the method.
  29. What is the purpose of a method signature in Java?
    Defines method's name and parameter types. Allows compiler to identify methods and validate calls.
  30. What distinguishes 'void run()' from 'int run()'?
    Return type. Return type differs but signature components are identical.
  31. What part of a method is not included in its signature?
    Return type. Only name and parameters define the signature for overloading.
  32. Which component of a method signature affects overloading?
    Parameter list. Return type cannot distinguish overloaded methods in Java.
  33. What does the method signature 'String toString()' imply?
    Returns a String. Method will return a String object when called.
  34. What does 'int compare(String a, String b)' return?
    int. The data type produced when method execution finishes.
  35. What is the parameter type in 'void print(double value)'?
    double. The data type of the single parameter accepted.
  36. What is the return type in 'boolean checkStatus()'?
    boolean. The data type returned when method executes successfully.
  37. What does a method signature determine for the compiler?
    Method calling conventions. Enables proper method resolution and type checking.
  38. State the rule for a valid Java method signature.
    Unique name and valid parameter list. Ensures method can be properly called and identified.

Study these flashcards