Java Test 3 – Easy–Medium Level

Welcome to your Java Test 3 – Easy–Medium Level

1. Which of the following is a correct method definition in Java?

2. What will the following code print?


int x = 10;
if (x > 5) {
     System.out.println("Greater than 5");
}

3. Which value does this expression return?


Math.max(4, 9);

4. What is the correct way to declare a class named Person?

5. What does this return?


String s = "Hello";
System.out.println(s.charAt(1));

6. Which of the following is true about for loops in Java?

7. What will this code print?


String a = "Hi";
String b = "Hi";
System.out.println(a == b);

8. How do you convert an int to a String in Java?

9. What does this print?


int[] arr = {1, 2, 3};
System.out.println(arr.length);

10. What will this return?


String text = "Java";
System.out.println(text.toUpperCase());

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