Methods/Functions

Methods/Functions

Basics of Methods, Method Calls and Execution, Method Overriding, Recursive Functions, Return Types and Parameters

1 / 10

Which of the following is true about method overloading in Java?

2 / 10

What will happen if the return statement is missing in a non-void method in Java?

3 / 10

What will the following code output?

void testMethod() {
System.out.println(“Hello”);
return;
System.out.println(“World”);
}

4 / 10

What is the result of this code?

public class Test {
static void method(int… nums) {
System.out.println(nums.length);
}
public static void main(String[] args) {
method(1, 2, 3, 4);
method();
}
}

5 / 10

Which of the following statements about method overriding is true?

6 / 10

What will happen if the following code is executed?

class Parent {
void display() {
System.out.println(“Parent”);
}
}
class Child extends Parent {
@Override
void display() {
System.out.println(“Child”);
}
}
public class Test {
public static void main(String[] args) {
Parent obj = new Child();
obj.display();
}
}

7 / 10

What will the following recursive function output?

int factorial(int n) {
if (n == 1) return 1;
return n * factorial(n – 1);
}
System.out.println(factorial(4));

8 / 10

Which of the following is a key property of recursive functions?

9 / 10

What is the output of the following code?

class Test {
static int square(int x) {
return x * x;
}
public static void main(String[] args) {
System.out.println(square(2.5));
}
}

10 / 10

What will the following code output?

class Test {
static void changeValue(int a) {
a = 20;
}
public static void main(String[] args) {
int x = 10;
changeValue(x);
System.out.println(x);
}
}

Your score is

Scroll to Top