Method Signatures - AP Computer Science A
- What determines the method to execute among overloaded methods?
- Parameter list matching. Compiler matches arguments to parameter types and count.
- In 'float calculate(double x)', what is the return type?
- float. The data type returned when method execution completes.
- Identify the components of a method signature.
- Method name and parameter list. These uniquely identify how to call the method.
- What distinguishes overloaded methods in Java?
- Different parameter lists. Same name but different parameters allows multiple versions.
- In 'double getValue()', what is the return type?
- double. The data type this method produces when called.
- Identify the method signature: 'void compute(int a, double b)'.
- compute(int, double). Return type and access modifier are excluded from signature.
- What is the return type in the signature: 'boolean check(int x)'?
- boolean. Indicates the method returns a boolean value.
- How does Java distinguish between two overloaded methods?
- By their parameter lists. Return type alone cannot differentiate overloaded methods.
- In 'char getChar()', what is the method's return type?
- char. The data type the method will return when executed.
- Find the error in 'void method(int x, int x)'.
- Duplicate parameter names. Parameter names must be unique within the method scope.
- 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.
- How many parameters are in 'void process(int a, float b, String c)'?
- Three parameters. Counts each comma-separated parameter in the list.
- What is the method name in 'boolean isValid(int a, int b)'?
- isValid. The identifier that appears before the parameter list.
- Identify the method name in the signature 'void draw()'.
- draw. The identifier used to invoke this method.
- Given the signature 'int add(int a, int b)', how many parameters are there?
- Two parameters. Counts the comma-separated parameters in parentheses.
- Which part of the method signature indicates its name?
- The method name itself. The identifier used to call the method.
- In 'void transform(int x)', what is the parameter type?
- int. The data type of the single parameter variable.
- Given 'void log()', identify a valid overloaded method.
- void log(String message). Adding parameters creates a different method signature.
- In the method signature 'void test()', what is the return type?
- void. Indicates no value is returned by this method.
- What does the parameter list in a method signature specify?
- Types and number of parameters. Determines what arguments can be passed to the method.
- State the rule for method overloading.
- Methods must differ in parameter types or number. Enables multiple methods with same name but different usage.
- What is the parameter type in 'String format(String pattern)'?
- String. The data type of the method's single parameter.
- Identify the method signature: 'public int compute(float num)'.
- compute(float). Access modifiers and return type are not part of signature.
- What does a void return type indicate in a method signature?
- Method returns no value. Indicates the method produces no output value.
- What is the parameter list in 'void setValues(int a, float b)'?
- int, float. The types of data the method accepts as input.
- Which method signature is a valid overload of 'void execute()'?
- void execute(int). Different parameter list makes this a valid overload.
- What is the effect of changing the parameter type in a signature?
- Creates an overloaded method. New signature allows method overloading to occur.
- Identify the error: 'double sum(int a, int a)'.
- Duplicate parameter names. Parameters must have unique names within the method.
- 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.
- What distinguishes 'void run()' from 'int run()'?
- Return type. Return type differs but signature components are identical.
- What part of a method is not included in its signature?
- Return type. Only name and parameters define the signature for overloading.
- Which component of a method signature affects overloading?
- Parameter list. Return type cannot distinguish overloaded methods in Java.
- What does the method signature 'String toString()' imply?
- Returns a String. Method will return a String object when called.
- What does 'int compare(String a, String b)' return?
- int. The data type produced when method execution finishes.
- What is the parameter type in 'void print(double value)'?
- double. The data type of the single parameter accepted.
- What is the return type in 'boolean checkStatus()'?
- boolean. The data type returned when method executes successfully.
- What does a method signature determine for the compiler?
- Method calling conventions. Enables proper method resolution and type checking.
- State the rule for a valid Java method signature.
- Unique name and valid parameter list. Ensures method can be properly called and identified.