Graded A+
Which of the following is true about method parameters in Java?
A) They must always be final
✔✔B) They allow data to be passed into a method
C) They must always be of type int
D) They cannot be used in constructors
What is required to call a static method in Java?
✔✔A) The method name prefixed with the class name
B) Creating an object of the class
C) Using the super keyword
D) Overriding the method in a subclass
Which return type should be used when a method does not return any value?
✔✔A) void
B) null
C) empty
1
,D) returnless
What will happen if a method is called with fewer arguments than required?
✔✔A) A compilation error occurs
B) The missing arguments are replaced with default values
C) The program skips the method execution
D) The method executes with null values
Which of the following correctly defines a method with multiple parameters?
A) `void display(int x int y) { }`
✔✔B) `void display(int x, int y) { }`
C) `void display(int x. int y) { }`
D) `void display(int x y) { }`
Which statement about method overriding is correct?
A) The overriding method must have a different name
B) The return type must be changed
✔✔C) The method must have the same signature as the one in the superclass
2
,D) The method can only be overridden in the same class
What does the return keyword do in a method?
A) It stops the entire program execution
B) It creates a new variable
✔✔C) It sends a value back to the calling method
D) It allows a method to be called again automatically
Which method declaration is correct?
✔✔A) `public int sum(int a, int b) { return a + b; }`
B) `void sum(int a, int b) { return a + b; }`
C) `int sum(int a, int b) return a + b;`
D) `int sum(int a, int b) { return; }`
What is the purpose of a default constructor?
✔✔A) To initialize an object without requiring parameters
B) To prevent object creation
C) To return a value when called
3
, D) To define static variables
Which of the following statements is true about method recursion?
A) It is not allowed in Java
B) It always results in infinite loops
✔✔C) It requires a base condition to prevent infinite calls
D) It can only be used inside static methods
What is the correct way to call a method inside another method of the same class?
✔✔A) `methodName();`
B) `this.methodName;`
C) `super.methodName();`
D) `new methodName();`
What happens when a method is declared as final?
A) It must return an integer
✔✔B) It cannot be overridden by subclasses
C) It can only be called once
4