Already Graded A
Which keyword is used to define a method in Java?
A) `return`
B) `method`
✔✔C) `void`
D) `class`
What happens if a method does not have a return type?
A) The program will not compile
✔✔B) The method must be declared with `void`
C) Java assigns `null` as the return type
D) The method is treated as a constructor
What is the correct way to define a method that takes two integer parameters?
A) `void sum { int a, int b }`
B) `method sum(int a, int b) { }`
✔✔C) `void sum(int a, int b) { }`
1
,D) `int sum(a, b) { return a + b; }`
Which of the following is true about a return statement in a method?
A) It must be used in all methods
B) It can be used only in `void` methods
✔✔C) It is used to send a value back to the caller
D) It stops the execution of the program
What is method overloading?
✔✔A) Defining multiple methods with the same name but different parameter lists
B) Defining multiple methods with the same name and same parameters
C) A method calling another method inside it
D) A method that calls itself
Which of the following correctly describes a recursive method?
A) A method that can only be called once
B) A method that returns multiple values
✔✔C) A method that calls itself
2
, D) A method that cannot have parameters
What will happen if a method is defined as `private`?
A) It can be accessed only from outside the class
B) It cannot return any value
✔✔C) It can be accessed only within the same class
D) It must be declared as `static`
Which of the following is a valid method signature?
A) `method calculate();`
✔✔B) `void calculate(int a, int b);`
C) `return calculate() void;`
D) `calculate void();`
What does the `static` keyword indicate in a method declaration?
✔✔A) The method belongs to the class rather than an instance of the class
B) The method cannot return a value
C) The method must be declared as `final`
3