WorksheetsJava_Methods Quiz
Total questions: 10
Worksheet time: 5mins
Why do we use methods in Java?
To make our code longer and complex
To copy the same code multiple times
To reuse, organize, and make code readable
To avoid using classes
What is the output of Math.pow(2, 3) in Java?
6
9
8.0
5.5
What keyword is used in Java to indicate that a method does not return any value?
null
return
empty
void
Which part of a method defines what inputs it needs?
Method body
Method return type
Parameters
Variables
What is the term for calling a method from another method (e.g., main() calling greetUser())?
Compiling
Overriding
Invoking
Declaring
What is the return type of this method: public static double calculateArea(double l, double w)?
void
int
double
String
When does the return statement stop a method’s execution?
Only at the end of the program
When all variables are declared
Immediately
Never
What’s the purpose of parameters in methods?
To make the method longer
To store return values
To accept input values
To print messages
In the method signature public static int sum(int a, int b), what is int a?
A return value
A method call
A parameter
A loop
What is the correct way to call the method greetUser() from main()?
greetUser;
main.greetUser();
call greetUser();
greetUser();
