intensepracticeacademy.com

Java Free Questions

HARD LEVEL • JAVA
Hard Level Java Quiz – 30 Questions
Java free questions
Answer all questions and click Submit Quiz to see your score.
Difficulty: Placement Level / Hard
Q1

1. What is the output of the following code?

public class Test {
    public static void main(String[] args) {
        int x = 5;
        System.out.println(x++ + ++x);
    }
}
Q2

2. What will this code print?

public class Test {
    public static void main(String[] args) {
        String s1 = "Java";
        String s2 = new String("Java");
        System.out.println(s1 == s2);
        System.out.println(s1.equals(s2));
    }
}
Q3

3. What is the output of this code?

public class Test {
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        a = a ^ b;
        b = a ^ b;
        a = a ^ b;
        System.out.println(a + " " + b);
    }
}
Q4

4. What will be printed?

public class Test {
    public static void main(String[] args) {
        System.out.println(10 + 20 + "Java" + 10 + 20);
    }
}
Q5

5. What is the output?

public class Test {
    public static void main(String[] args) {
        int i = 0;
        for (; i < 3; ) {
            System.out.print(i + " ");
            i++;
        }
    }
}
Q6

6. What happens when this code is compiled and run?

interface A {
    default void show() {
        System.out.println("A");
    }
}
interface B {
    default void show() {
        System.out.println("B");
    }
}
public class Test implements A, B {
    public static void main(String[] args) {
        new Test().show();
    }
}
Q7

7. You have an immutable class in Java. Which one is a necessary condition?

class Point {
    private int x;
    private int y;
    // ...
}
Q8

8. What is the output?

public class Test {
    public static void main(String[] args) {
        String s = "abc";
        s.concat("def");
        System.out.println(s);
    }
}
Q9

9. What is the output of this program?

class Parent {
    int value = 10;
}
class Child extends Parent {
    int value = 20;
}
public class Test {
    public static void main(String[] args) {
        Parent p = new Child();
        System.out.println(p.value);
    }
}
Q10

10. Which collection guarantees that insertion order is preserved?

Q11

11. What happens when this code runs?

public class Test {
    public static void main(String[] args) {
        try {
            System.out.println("Try");
            System.exit(0);
        } finally {
            System.out.println("Finally");
        }
    }
}
Q12

12. What is the output?

public class Test {
    public static void change(String s) {
        s = s + "X";
    }
    public static void main(String[] args) {
        String s = "Hi";
        change(s);
        System.out.println(s);
    }
}
Q13

13. What will be printed?

public class Test {
    public static void main(String[] args) {
        int a = 5;
        System.out.println(a++ + a++ + ++a);
    }
}
Q14

14. What will happen?

public class Test {
    public static void main(String[] args) {
        int[] arr = new int[-5];
        System.out.println(arr.length);
    }
}
Q15

15. You want a thread-safe list with good read performance and infrequent writes. Which collection is best?

Q16

16. What is the output?

public class Test {
    public static void main(String[] args) {
        String s1 = "java";
        String s2 = "ja" + "va";
        System.out.println(s1 == s2);
    }
}
Q17

17. Find the error / behaviour:

public class Test {
    public static void main(String[] args) {
        String s = null;
        System.out.println(s.length());
    }
}
Q18

18. Which statement about overloading and overriding is TRUE?

Q19

19. What is the output?

class A {
    static void show() {
        System.out.println("A");
    }
}
class B extends A {
    static void show() {
        System.out.println("B");
    }
}
public class Test {
    public static void main(String[] args) {
        A obj = new B();
        obj.show();
    }
}
Q20

20. What will be printed?

public class Test {
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder("abc");
        String s = sb.toString();
        sb.append("def");
        System.out.println(s);
    }
}
Q21

21. Which keyword is used to prevent inheritance of a class?

Q22

22. Find the behaviour of this code:

public class Test {
    public static void main(String[] args) {
        int x = 0;
        System.out.println(10 / x);
    }
}
Q23

23. You want to sort a custom class with multiple fields. Which interface should the class implement for natural ordering?

Q24

24. What is the output?

public class Test {
    public static void main(String[] args) {
        boolean b1 = true;
        boolean b2 = false;
        if (b1 = false || b2) {
            System.out.println("Hello");
        } else {
            System.out.println("World");
        }
    }
}
Q25

25. What is the output?

public class Test {
    public static void main(String[] args) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 2; j++) {
                if (i == 1) break;
                System.out.print(i + "" + j + " ");
            }
        }
    }
}
Q26

26. What happens here?

abstract class A {
    abstract void show();
}
public class Test extends A {
    // missing implementation
}
Q27

27. Which is TRUE about String, StringBuilder, StringBuffer?

Q28

28. What is the output?

class Test {
    static {
        System.out.print("Static ");
    }
    public static void main(String[] args) {
        System.out.print("Main ");
    }
}
Q29

29. In a try-with-resources statement, which interface must the resource implement?

Q30

30. What is the output?

public class Test {
    public static void main(String[] args) {
        int x = 1;
        do {
            System.out.print(x + " ");
            x = x * 2;
        } while (x < 10);
    }
}
✅ Green – Correct | ❌ Red – Incorrect / Not Attempted

Java Hard Level MCQ Quiz – Frequently Asked Questions

1. Who can use this hard level Java MCQ quiz?

This quiz is designed for final year students, freshers preparing for IT placements, and anyone who already knows Java basics and wants to practice tricky, interview-level questions.

2. What types of questions are included in this quiz?

The quiz includes a mix of output-based questions, error-finding questions, tricky loops, OOP concepts, exception handling, collections and scenario-based problems commonly asked in interviews.

3. How many questions are there and what is the difficulty level?

This quiz contains 30 hard level multiple-choice questions. Most questions are at placement and technical interview difficulty, not beginner level.

4. Will I get answers and score instantly?

Yes. After you click the “Submit Quiz & View Result” button, you will see your total score, number of correct and wrong answers, percentage and the correct option for each question.

5. Is this quiz free to attempt?

Yes, this Java hard level MCQ quiz is completely free to attempt on Intense Practice Academy. You can use it any number of times for practice.

6. How is this quiz helpful for placements and interviews?

These questions help you practice tricky areas like output prediction, pass-by-value behavior, immutability, static methods, collections, exceptions and nested loops, which are very common in technical rounds and online tests.

7. Can I reattempt the quiz multiple times?

Yes, you can reattempt the quiz as many times as you want. Repeating hard questions improves your speed, accuracy and confidence before real exams.

8. Do you have more Java MCQs and other subjects?

Yes. Intense Practice Academy provides more Java MCQ sets, as well as C, Python, Aptitude and Reasoning questions. You can explore our free pages and paid MCQ packs for complete placement preparation.

⭐ Upgrade Your Prep with 1000+ MCQs

Practice is powerful. Combine these coding questions with our C, Java & Python MCQ Pack (2025 Edition) for complete placement preparation.

🎁 Bonus: Early learners get extra aptitude practice sets and updates from Intense Practice Academy.