Java Test 4 – Medium Level

Welcome to your Java Test 4 – Medium Level

1. What does the following code print?


int x = 3;
int y = 4;
System.out.println(x * y + y);

2. Which of the following keywords is used to inherit from a class?

3. What will this code print?


for (int i = 0; i < 3; i++) {
Β  Β  Β  System.out.print(i + " ");
}

4. What is the output of this code?


boolean a = true;
boolean b = false;
System.out.println(a && b);

5. What does this code print?


int a = 2;
int b = 5;
if (a > b) {
Β  Β System.out.println("A");
} else {
Β  Β System.out.println("B");
}

6. What is printed by this code?


String s = "abc";
System.out.println(s.indexOf("b"));

7. What is a constructor in Java?

8. What will this code print?


int[] numbers = {10, 20, 30};
System.out.println(numbers[1]);

9. What is the output of this code?


String s = "Java";
System.out.println(s.equals("java"));

10. What happens if you try to access an index outside the array bounds?

Did you like it? Don’t keep it to yourself β€” share it like juicy gossip! 😏