Java Method Declaration Quiz Form
Test your knowledge of Java method declarations. Answer all questions to the best of your ability.
Which of the following is the correct syntax for declaring a method that returns an integer and takes no parameters?
*
int myMethod() { }
int myMethod[] { }
myMethod() int { }
void myMethod(int) { }
What is the return type of the following method? public static double calculateArea(double radius) { ... }
*
Select all valid Java method declarations below.
*
public void start() { }
private int sum(int a, int b) { }
static String getName(String s) { }
public static void main[] { }
Which keyword is used to indicate a method does not return any value?
*
void
null
empty
return
Write a method declaration for a public static method named 'printMessage' that takes a String parameter and returns nothing.
*
Which access modifier allows a method to be accessed only within its own class?
*
private
public
protected
default
Can a Java method have more than one parameter? If yes, how are they separated?
*
Yes, separated by commas
Yes, separated by semicolons
No, only one parameter is allowed
Yes, separated by spaces
Which of these is NOT a valid method name in Java?
*
_calculateTotal
2ndMethod
print
getValue
How do you declare a method that can be called without creating an object of the class?
*
Include the static keyword
Include the public keyword
Include the private keyword
Include the final keyword
What is method overloading in Java?
*
Defining multiple methods with the same name but different parameter lists
Defining multiple methods with different names in the same class
Calling a method from another class
Defining a method inside another method
Submit Quiz
Should be Empty: