Methods Flashcards
What is not an acceptable method declaration?
public static void doWork(int number, void thing) {
}
A user calls a method with the following syntax:
doSomething(3,”Hello”);
What could represent the Java method signature for the method they are calling?
public static void doSomething(int number, String text) { //some code }
What lines of code could be added to the following method to make it semantically and syntactically correct?
public static double someMethod(){
int a = 5; double b = 5.0; String c = "5"; char d = '5';
}
return b
The code below shows a method declaration and a call to that method.
public static int doSomething(int number){
return “’“+number+”’”;
}
String x = doSomething(5);
There is an error. What single change could resolve the error?
Change the method’s return type.
True or False?
The type of a variable passed into a method must match the type of the corresponding parameter in the method declaration.
True
True or False?
The name of a variable passed into a method must match the name of the corresponding parameter in the method declaration.
False
Can a method omit a return statement?
Yes, when the method’s return type is void
What is the correct type for a method that does not return a value?
Void