[
  {
    "id": 1,
    "question": "What is the output of the following Java program?",
    "code": "class Test {\n    public static void main(String[] args) {\n        String s1 = \"Java\";\n        String s2 = new String(\"Java\");\n        System.out.println((s1 == s2) + \" \" + s1.equals(s2));\n    }\n}",
    "image": "",
    "option1": "true true",
    "option2": "false true",
    "option3": "true false",
    "option4": "false false",
    "answer": 2,
    "otherInfo": "s1 points to String Constant Pool while s2 points to Heap memory; hence '==' gives false, but equals() compares actual content."
  },
  {
    "id": 2,
    "question": "What will happen when you execute the following code snippet?",
    "code": "class Parent {\n    void show() { System.out.println(\"Parent\"); }\n}\nclass Child extends Parent {\n    void show() { System.out.println(\"Child\"); }\n}\npublic class Main {\n    public static void main(String[] args) {\n        Parent p = new Child();\n        p.show();\n    }\n}",
    "image": "",
    "option1": "Prints: Parent",
    "option2": "Prints: Child",
    "option3": "Compilation Error",
    "option4": "Runtime Exception",
    "answer": 2,
    "otherInfo": "Method overriding resolved at runtime (Dynamic Method Dispatch) based on the object instance creation."
  },
  {
    "id": 3,
    "question": "Which of the following is true regarding default methods in Java 8 interfaces?",
    "code": "",
    "image": "",
    "option1": "They must be explicitly declared static.",
    "option2": "They allow adding new functionalities to existing interfaces without breaking implementing classes.",
    "option3": "Interfaces with default methods cannot be implemented by classes.",
    "option4": "Default methods cannot be overridden by implementing classes.",
    "answer": 2,
    "otherInfo": "Default methods introduced in Java 8 allow interface evolution backward compatibility."
  },
  {
    "id": 4,
    "question": "What will be the result of compiling and running this code?",
    "code": "public class TryCatchTest {\n    public static int test() {\n        try {\n            return 1;\n        } catch (Exception e) {\n            return 2;\n        } finally {\n            return 3;\n        }\n    }\n    public static void main(String[] args) {\n        System.out.println(test());\n    }\n}",
    "image": "",
    "option1": "1",
    "option2": "2",
    "option3": "3",
    "option4": "Compilation Error",
    "answer": 3,
    "otherInfo": "The finally block always executes, and returning from finally overrides any previous return statements in try or catch blocks."
  },
  {
    "id": 5,
    "question": "Which Collection implementation guarantees element uniqueness and preserves insertion order?",
    "code": "",
    "image": "",
    "option1": "HashSet",
    "option2": "TreeSet",
    "option3": "LinkedHashSet",
    "option4": "ArrayList",
    "answer": 3,
    "otherInfo": "LinkedHashSet uses a hash table along with a doubly-linked list running through all entries to maintain insertion order."
  },
  {
    "id": 6,
    "question": "What is the result of the following program?",
    "code": "public class ArrayTest {\n    public static void main(String[] args) {\n        int[] arr = new int[5];\n        System.out.println(arr[0]);\n    }\n}",
    "image": "",
    "option1": "Garbage Value",
    "option2": "0",
    "option3": "null",
    "option4": "ArrayIndexOutOfBoundsException",
    "answer": 2,
    "otherInfo": "Array elements are automatically initialized to default values of their types (0 for primitive int)."
  },
  {
    "id": 7,
    "question": "What will be printed by the following code?",
    "code": "public class LoopTest {\n    public static void main(String[] args) {\n        int x = 0;\n        for (int i = 0; i < 5; i++) {\n            if (i == 2) continue;\n            x += i;\n        }\n        System.out.println(x);\n    }\n}",
    "image": "",
    "option1": "10",
    "option2": "8",
    "option3": "6",
    "option4": "12",
    "answer": 2,
    "otherInfo": "Values added to x are 0 + 1 + 3 + 4 = 8 (2 is skipped by continue)."
  },
  {
    "id": 8,
    "question": "What happens if a thread calls start() twice on the same Thread instance?",
    "code": "Thread t = new Thread();\nt.start();\nt.start();",
    "image": "",
    "option1": "Thread starts executing again.",
    "option2": "It is ignored silently.",
    "option3": "IllegalThreadStateException is thrown at runtime.",
    "option4": "Compilation Error occurs.",
    "answer": 3,
    "otherInfo": "Once a thread reaches dead/terminated state or starts running, calling start() again throws IllegalThreadStateException."
  },
  {
    "id": 9,
    "question": "What will be the outcome of the following string operation?",
    "code": "public class StringTest {\n    public static void main(String[] args) {\n        String s = \"Hello\";\n        s.concat(\" World\");\n        System.out.println(s);\n    }\n}",
    "image": "",
    "option1": "Hello World",
    "option2": "Hello",
    "option3": "World",
    "option4": "NullPointerException",
    "answer": 2,
    "otherInfo": "Strings are immutable in Java. s.concat(\" World\") returns a new string, but s reference remains unchanged."
  },
  {
    "id": 10,
    "question": "Which keyword prevents a class from being subclassed in Java?",
    "code": "",
    "image": "",
    "option1": "static",
    "option2": "abstract",
    "option3": "final",
    "option4": "private",
    "answer": 3,
    "otherInfo": "Declaring a class final disables inheritance for that class."
  },
  {
    "id": 11,
    "question": "What will be printed when running this program?",
    "code": "public class ExceptionTest {\n    public static void main(String[] args) {\n        try {\n            int x = 10 / 0;\n        } catch (ArithmeticException e) {\n            System.out.print(\"A \");\n        } catch (Exception e) {\n            System.out.print(\"B \");\n        }\n    }\n}",
    "image": "",
    "option1": "A",
    "option2": "B",
    "option3": "A B",
    "option4": "Compilation error due to catch block order",
    "answer": 1,
    "otherInfo": "ArithmeticException is caught by the first matching catch block. Specific exceptions must precede general Exception blocks."
  },
  {
    "id": 12,
    "question": "Which interface must a class implement to allow its instances to be sorted using Collections.sort(list)?",
    "code": "",
    "image": "",
    "option1": "Comparator",
    "option2": "Comparable",
    "option3": "Cloneable",
    "option4": "Serializable",
    "answer": 2,
    "otherInfo": "Comparable interface (compareTo method) defines natural sorting order for objects."
  },
  {
    "id": 13,
    "question": "What is the output of the following switch expression/statement?",
    "code": "public class SwitchTest {\n    public static void main(String[] args) {\n        int number = 2;\n        switch (number) {\n            case 1: System.out.print(\"1 \");\n            case 2: System.out.print(\"2 \");\n            case 3: System.out.print(\"3 \");\n            default: System.out.print(\"4\");\n        }\n    }\n}",
    "image": "",
    "option1": "2",
    "option2": "2 3 4",
    "option3": "2 3",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "Without break statements, execution falls through all subsequent cases starting from case 2."
  },
  {
    "id": 14,
    "question": "Which component of Java is responsible for running bytecode directly across different platforms?",
    "code": "",
    "image": "",
    "option1": "JDK",
    "option2": "JVM",
    "option3": "JRE",
    "option4": "JDB",
    "answer": 2,
    "otherInfo": "The JVM (Java Virtual Machine) provides the runtime environment to execute bytecode."
  },
  {
    "id": 15,
    "question": "What will be the output of the following program?",
    "code": "public class OverloadTest {\n    static void print(int a) { System.out.println(\"int\"); }\n    static void print(Integer a) { System.out.println(\"Integer\"); }\n    public static void main(String[] args) {\n        byte b = 10;\n        print(b);\n    }\n}",
    "image": "",
    "option1": "int",
    "option2": "Integer",
    "option3": "Compilation Error",
    "option4": "ClassCastException",
    "answer": 1,
    "otherInfo": "Primitive widening (byte to int) takes precedence over autoboxing (byte to Byte/Integer)."
  },
  {
    "id": 16,
    "question": "Which map implementation allows a single null key and multiple null values?",
    "code": "",
    "image": "",
    "option1": "TreeMap",
    "option2": "ConcurrentHashMap",
    "option3": "Hashtable",
    "option4": "HashMap",
    "answer": 4,
    "otherInfo": "HashMap permits one null key and multiple null values, unlike Hashtable and ConcurrentHashMap."
  },
  {
    "id": 17,
    "question": "What will be printed by this code block?",
    "code": "public class StaticTest {\n    static int count = 0;\n    StaticTest() {\n        count++;\n    }\n    public static void main(String[] args) {\n        new StaticTest();\n        new StaticTest();\n        System.out.println(count);\n    }\n}",
    "image": "",
    "option1": "0",
    "option2": "1",
    "option3": "2",
    "option4": "Compilation Error",
    "answer": 3,
    "otherInfo": "Static variables are shared across all instances of a class. Increment occurs twice."
  },
  {
    "id": 18,
    "question": "Which thread state is entered when a thread calls Object.wait()?",
    "code": "",
    "image": "",
    "option1": "BLOCKED",
    "option2": "WAITING",
    "option3": "TIMED_WAITING",
    "option4": "TERMINATED",
    "answer": 2,
    "otherInfo": "Calling Object.wait() without a timeout puts the thread into the WAITING state."
  },
  {
    "id": 19,
    "question": "What is the output of the following code snippet?",
    "code": "public class StringBuilderTest {\n    public static void main(String[] args) {\n        StringBuilder sb = new StringBuilder(\"Java\");\n        sb.append(\"8\");\n        System.out.println(sb);\n    }\n}",
    "image": "",
    "option1": "Java",
    "option2": "Java8",
    "option3": "8",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "StringBuilder is mutable; append directly modifies the existing StringBuilder instance."
  },
  {
    "id": 20,
    "question": "What will be the output of the following array length operation?",
    "code": "public class ArrayLen {\n    public static void main(String[] args) {\n        int[][] arr = new int[3][5];\n        System.out.println(arr.length + \" \" + arr[0].length);\n    }\n}",
    "image": "",
    "option1": "3 5",
    "option2": "5 3",
    "option3": "15 5",
    "option4": "3 15",
    "answer": 1,
    "otherInfo": "arr.length represents the number of rows (3), and arr[0].length represents columns in the first row (5)."
  },
  {
    "id": 21,
    "question": "Which exception is thrown when attempting to store an element of an incompatible type into an object array?",
    "code": "",
    "image": "",
    "option1": "ClassCastException",
    "option2": "ArrayStoreException",
    "option3": "IllegalArgumentException",
    "option4": "IllegalStateException",
    "answer": 2,
    "otherInfo": "ArrayStoreException is thrown at runtime when inserting an element of an improper type into an array of objects."
  },
  {
    "id": 22,
    "question": "What is the output of the following program?",
    "code": "public class TernaryTest {\n    public static void main(String[] args) {\n        int a = 5;\n        int b = 10;\n        int res = (a > b) ? a++ : b++;\n        System.out.println(a + \" \" + b);\n    }\n}",
    "image": "",
    "option1": "5 10",
    "option2": "6 11",
    "option3": "5 11",
    "option4": "6 10",
    "answer": 3,
    "otherInfo": "Since (a > b) is false, only b++ is evaluated (post-increment), leaving a unchanged at 5 and b becoming 11."
  },
  {
    "id": 23,
    "question": "Which of the following modifiers cannot be used with a top-level class?",
    "code": "",
    "image": "",
    "option1": "public",
    "option2": "abstract",
    "option3": "private",
    "option4": "final",
    "answer": 3,
    "otherInfo": "Top-level classes can only have public or default (package-private) access specifiers."
  },
  {
    "id": 24,
    "question": "What is the default capacity of an ArrayList when initialized using the no-arg constructor `new ArrayList<>()`?",
    "code": "",
    "image": "",
    "option1": "0 initially, expands to 10 on first element addition",
    "option2": "16",
    "option3": "5",
    "option4": "12",
    "answer": 1,
    "otherInfo": "In modern JDKs, default constructor initializes an empty array, which expands to 10 upon adding the first element."
  },
  {
    "id": 25,
    "question": "What is the output of the code below?",
    "code": "public class ExceptionFlow {\n    public static void main(String[] args) {\n        try {\n            throw new NullPointerException();\n        } catch (Exception e) {\n            System.out.print(\"Caught \");\n        }\n        System.out.print(\"Done\");\n    }\n}",
    "image": "",
    "option1": "Caught",
    "option2": "Done",
    "option3": "Caught Done",
    "option4": "Uncaught Exception Exception",
    "answer": 3,
    "otherInfo": "Exception is handled smoothly in the catch block, and execution proceeds normally to printing 'Done'."
  },
  {
    "id": 26,
    "question": "What does the `volatile` keyword guarantee in Java multithreading?",
    "code": "",
    "image": "",
    "option1": "Atomicity of complex operations",
    "option2": "Visibility of variable changes across threads and instruction reordering constraints",
    "option3": "Mutual exclusion locking",
    "option4": "Thread synchronization blocking",
    "answer": 2,
    "otherInfo": "Volatile ensures modifications are written directly to main memory, guaranteeing visibility across threads."
  },
  {
    "id": 27,
    "question": "What will be printed by the following program?",
    "code": "public class EqualityTest {\n    public static void main(String[] args) {\n        Integer x = 127;\n        Integer y = 127;\n        Integer a = 128;\n        Integer b = 128;\n        System.out.println((x == y) + \" \" + (a == b));\n    }\n}",
    "image": "",
    "option1": "true true",
    "option2": "true false",
    "option3": "false false",
    "option4": "false true",
    "answer": 2,
    "otherInfo": "Java caches Integer objects in the range -128 to 127. Values outside this range create separate object instances on the heap."
  },
  {
    "id": 28,
    "question": "Which interface represents a task that can be executed by a thread and can return a result or throw an exception?",
    "code": "",
    "image": "",
    "option1": "Runnable",
    "option2": "Callable",
    "option3": "Thread",
    "option4": "Future",
    "answer": 2,
    "otherInfo": "Callable interface has call() method which returns a result and can throw checked exceptions."
  },
  {
    "id": 29,
    "question": "What will be the output of this code snippet?",
    "code": "public class CastTest {\n    public static void main(String[] args) {\n        double d = 10.5;\n        int i = (int) d;\n        System.out.println(i);\n    }\n}",
    "image": "",
    "option1": "10.5",
    "option2": "10",
    "option3": "11",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "Explicit downcasting from double to int truncates the decimal portion."
  },
  {
    "id": 30,
    "question": "What will be the output of the following program?",
    "code": "class A {\n    static {\n        System.out.print(\"Static \");\n    }\n    {\n        System.out.print(\"Instance \");\n    }\n    A() {\n        System.out.print(\"Constructor \");\n    }\n}\npublic class Main {\n    public static void main(String[] args) {\n        new A();\n    }\n}",
    "image": "",
    "option1": "Instance Static Constructor",
    "option2": "Static Instance Constructor",
    "option3": "Constructor Instance Static",
    "option4": "Static Constructor Instance",
    "answer": 2,
    "otherInfo": "Static blocks execute when the class is loaded, followed by instance initializer blocks, and then the constructor runs upon object creation."
  },
  {
    "id": 31,
    "question": "What will be the output of the following program?",
    "code": "public class StringPoolTest {\n    public static void main(String[] args) {\n        String s1 = new String(\"Java\");\n        String s2 = s1.intern();\n        String s3 = \"Java\";\n        System.out.println((s1 == s2) + \" \" + (s2 == s3));\n    }\n}",
    "image": "",
    "option1": "true true",
    "option2": "false true",
    "option3": "false false",
    "option4": "true false",
    "answer": 2,
    "otherInfo": "intern() returns the reference from the String Constant Pool. s2 and s3 both refer to the pool object, while s1 points to the heap object."
  },
  {
    "id": 32,
    "question": "Which of the following statements is true regarding covariant return types in Java?",
    "code": "",
    "image": "",
    "option1": "An overriding method can return any type regardless of the superclass method's return type.",
    "option2": "An overriding method can return a subtype of the return type declared in the superclass method.",
    "option3": "Covariant return types are only allowed for primitive data types.",
    "option4": "Covariant return types were introduced in Java 17.",
    "answer": 2,
    "otherInfo": "Since Java 5, an overriding method can specify a return type that is a subclass/subtype of the type returned by the overridden method."
  },
  {
    "id": 33,
    "question": "What will be the output of the following code?",
    "code": "public class ShadowTest {\n    int x = 10;\n    public void printValue() {\n        int x = 20;\n        System.out.println(this.x + \" \" + x);\n    }\n    public static void main(String[] args) {\n        new ShadowTest().printValue();\n    }\n}",
    "image": "",
    "option1": "10 10",
    "option2": "20 20",
    "option3": "10 20",
    "option4": "20 10",
    "answer": 3,
    "otherInfo": "this.x refers to the instance variable (10), while x refers to the local variable inside printValue() (20)."
  },
  {
    "id": 34,
    "question": "What happens when you compile and run the following code?",
    "code": "public class ThrowTest {\n    public static void main(String[] args) {\n        try {\n            throw null;\n        } catch (Exception e) {\n            System.out.println(e.getClass().getName());\n        }\n    }\n}",
    "image": "",
    "option1": "Compilation Error",
    "option2": "Prints: java.lang.NullPointerException",
    "option3": "Prints: java.lang.Exception",
    "option4": "Terminates abruptly with unhandled null",
    "answer": 2,
    "otherInfo": "Throwing a null reference causes the JVM to implicitly throw a NullPointerException at runtime."
  },
  {
    "id": 35,
    "question": "What is the result of executing this code snippet?",
    "code": "public class BitwiseTest {\n    public static void main(String[] args) {\n        int a = 5; // 0101\n        int b = 3; // 0011\n        System.out.println((a & b) + \" \" + (a | b) + \" \" + (a ^ b));\n    }\n}",
    "image": "",
    "option1": "1 7 6",
    "option2": "1 7 7",
    "option3": "3 5 6",
    "option4": "0 7 6",
    "answer": 1,
    "otherInfo": "Bitwise AND (5 & 3 = 1), Bitwise OR (5 | 3 = 7), and Bitwise XOR (5 ^ 3 = 6)."
  },
  {
    "id": 36,
    "question": "Which collection implementation uses a Red-Black tree under the hood to store elements in sorted order?",
    "code": "",
    "image": "",
    "option1": "HashSet",
    "option2": "LinkedHashSet",
    "option3": "TreeSet",
    "option4": "PriorityQueue",
    "answer": 3,
    "otherInfo": "TreeSet is backed by a NavigableMap (specifically TreeMap), which uses a Red-Black tree structure to maintain natural order."
  },
  {
    "id": 37,
    "question": "What will be the output of the following code?",
    "code": "public class ArrayCopyTest {\n    public static void main(String[] args) {\n        int[] a = {1, 2, 3};\n        int[] b = a;\n        b[0] = 99;\n        System.out.println(a[0]);\n    }\n}",
    "image": "",
    "option1": "1",
    "option2": "99",
    "option3": "0",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "Arrays are objects in Java. Assigning b = a copies the reference, so both variables point to the same array in heap memory."
  },
  {
    "id": 38,
    "question": "What is the purpose of the `join()` method in the Thread class?",
    "code": "",
    "image": "",
    "option1": "It merges two running threads into a single process.",
    "option2": "It forces the current thread to pause until the thread on which join() was called terminates.",
    "option3": "It places the thread back into the pool of ready-to-run threads.",
    "option4": "It allows threads to share local variables.",
    "answer": 2,
    "otherInfo": "join() blocks the calling thread until the target thread finishes execution."
  },
  {
    "id": 39,
    "question": "What will be the output of the following program?",
    "code": "public class StringEquals {\n    public static void main(String[] args) {\n        String s1 = \"abc\";\n        StringBuffer s2 = new StringBuffer(\"abc\");\n        System.out.println(s1.equals(s2));\n    }\n}",
    "image": "",
    "option1": "true",
    "option2": "false",
    "option3": "Compilation Error",
    "option4": "ClassCastException",
    "answer": 2,
    "otherInfo": "String.equals() checks if the object is an instance of String first. Since StringBuffer is not a String, it returns false."
  },
  {
    "id": 40,
    "question": "What is the result of compiling and executing this code?",
    "code": "class Parent {\n    static void display() { System.out.print(\"Parent \"); }\n}\nclass Child extends Parent {\n    static void display() { System.out.print(\"Child \"); }\n}\npublic class Main {\n    public static void main(String[] args) {\n        Parent p = new Child();\n        p.display();\n    }\n}",
    "image": "",
    "option1": "Child ",
    "option2": "Parent ",
    "option3": "Compilation Error",
    "option4": "Parent Child ",
    "answer": 2,
    "otherInfo": "Static methods cannot be overridden; they are hidden (Method Hiding). Static methods are resolved at compile time using the reference type (Parent)."
  },
  {
    "id": 41,
    "question": "Which functional interface method signature matches `java.util.function.Predicate<T>`?",
    "code": "",
    "image": "",
    "option1": "void accept(T t)",
    "option2": "T get()",
    "option3": "boolean test(T t)",
    "option4": "R apply(T t)",
    "answer": 3,
    "otherInfo": "Predicate<T> has a single abstract method boolean test(T t) which evaluates a condition and returns a boolean."
  },
  {
    "id": 42,
    "question": "What will be printed by the following code?",
    "code": "public class LoopBreakTest {\n    public static void main(String[] args) {\n        outer:\n        for (int i = 0; i < 3; i++) {\n            for (int j = 0; j < 3; j++) {\n                if (i == 1 && j == 1) break outer;\n                System.out.print(i + \"\" + j + \" \");\n            }\n        }\n    }\n}",
    "image": "",
    "option1": "00 01 02 10 11 ",
    "option2": "00 01 02 10 ",
    "option3": "00 01 02 10 12 20 21 22 ",
    "option4": "00 01 02 ",
    "answer": 2,
    "otherInfo": "The labeled break statement `break outer;` immediately terminates the outer loop when i=1 and j=1."
  },
  {
    "id": 43,
    "question": "What is the output of the following code?",
    "code": "public class AutoBoxingTest {\n    public static void main(String[] args) {\n        Long l1 = 100L;\n        Long l2 = 100L;\n        System.out.println(l1 == l2);\n    }\n}",
    "image": "",
    "option1": "true",
    "option2": "false",
    "option3": "Compilation Error",
    "option4": "ClassCastException",
    "answer": 1,
    "otherInfo": "Like Integer, Long also caches values between -128 and 127, so l1 and l2 refer to the exact same cached object."
  },
  {
    "id": 44,
    "question": "Which exception is thrown if you attempt to modify a collection while iterating over it using a standard Iterator (without using Iterator's remove method)?",
    "code": "",
    "image": "",
    "option1": "IllegalStateException",
    "option2": "ConcurrentModificationException",
    "option3": "UnsupportedOperationException",
    "option4": "NoSuchElementException",
    "answer": 2,
    "otherInfo": "Fail-fast iterators throw ConcurrentModificationException if the underlying collection is modified during iteration."
  },
  {
    "id": 45,
    "question": "What will be the output of the following program?",
    "code": "public class FinallyExitTest {\n    public static void main(String[] args) {\n        try {\n            System.out.print(\"Try \");\n            System.exit(0);\n        } finally {\n            System.out.print(\"Finally \");\n        }\n    }\n}",
    "image": "",
    "option1": "Try Finally ",
    "option2": "Try ",
    "option3": "Finally ",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "System.exit(0) terminates the JVM process immediately, preventing the execution of the finally block."
  },
  {
    "id": 46,
    "question": "What will happen during the compilation or execution of this code?",
    "code": "interface A { default void hello() { System.out.print(\"A\"); } }\ninterface B { default void hello() { System.out.print(\"B\"); } }\nclass C implements A, B {}\npublic class Main {\n    public static void main(String[] args) {\n        new C().hello();\n    }\n}",
    "image": "",
    "option1": "Prints: A",
    "option2": "Prints: B",
    "option3": "Compilation Error due to duplicate default method implementation",
    "option4": "Runtime Exception",
    "answer": 3,
    "otherInfo": "Class C causes the Diamond Problem by inheriting conflicting default methods from A and B without explicitly overriding hello()."
  },
  {
    "id": 47,
    "question": "Which keyword is used to explicitly call a superclass constructor from a subclass constructor?",
    "code": "",
    "image": "",
    "option1": "this",
    "option2": "super",
    "option3": "extends",
    "option4": "parent",
    "answer": 2,
    "otherInfo": "The super() call invokes the superclass constructor and must be the first statement in the subclass constructor."
  },
  {
    "id": 48,
    "question": "What is the output of the following program?",
    "code": "public class VarArgsTest {\n    static void display(int... num) {\n        System.out.println(num.length);\n    }\n    public static void main(String[] args) {\n        display();\n    }\n}",
    "image": "",
    "option1": "0",
    "option2": "null",
    "option3": "Compilation Error",
    "option4": "NullPointerException",
    "answer": 1,
    "otherInfo": "Passing no parameters to a varargs method initializes the parameter as an empty array of length 0."
  },
  {
    "id": 49,
    "question": "Which of the following classes is thread-safe for legacy vector/list operations?",
    "code": "",
    "image": "",
    "option1": "ArrayList",
    "option2": "LinkedList",
    "option3": "Vector",
    "option4": "ArrayDeque",
    "answer": 3,
    "otherInfo": "Vector is a legacy thread-safe synchronized collection class from Java 1.0."
  },
  {
    "id": 50,
    "question": "What will be printed when running this program?",
    "code": "public class StringTrimTest {\n    public static void main(String[] args) {\n        String str = \" \";\n        System.out.println(str.trim().isEmpty() + \" \" + str.isBlank());\n    }\n}",
    "image": "",
    "option1": "false false",
    "option2": "true true",
    "option3": "false true",
    "option4": "true false",
    "answer": 2,
    "otherInfo": "trim().isEmpty() checks if the trimmed length is 0 (true), and isBlank() (introduced in Java 11) checks if the string contains only white spaces (true)."
  },
  {
    "id": 51,
    "question": "What is the result of the following assignment?",
    "code": "public class PromotionTest {\n    public static void main(String[] args) {\n        byte a = 10;\n        byte b = 20;\n        // byte c = a + b;\n        System.out.println(a + b);\n    }\n}",
    "image": "",
    "option1": "Prints 30; `byte c = a + b;` compiles fine.",
    "option2": "Prints 30; `byte c = a + b;` fails compilation because arithmetic operations promote primitives to int.",
    "option3": "Compilation error at `System.out.println(a + b)`.",
    "option4": "Prints 1020.",
    "answer": 2,
    "otherInfo": "In Java, binary arithmetic operators automatically promote byte, short, or char operands to int type."
  },
  {
    "id": 52,
    "question": "What will be the output of the following thread execution?",
    "code": "class MyRunnable implements Runnable {\n    public void run() {\n        System.out.print(\"Run \");\n    }\n}\npublic class ThreadTest {\n    public static void main(String[] args) {\n        Thread t = new Thread(new MyRunnable());\n        t.run();\n        System.out.print(\"Main \");\n    }\n}",
    "image": "",
    "option1": "Main Run ",
    "option2": "Run Main ",
    "option3": "Output is non-deterministic.",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "Calling run() directly executes the method on the current main thread synchronously like a standard method call, so 'Run Main ' is printed sequentially."
  },
  {
    "id": 53,
    "question": "What is the output of the following garbage collection question?",
    "code": "public class GCTest {\n    @Override\n    protected void finalize() {\n        System.out.print(\"Finalized \");\n    }\n    public static void main(String[] args) {\n        GCTest obj = new GCTest();\n        obj = null;\n        System.gc();\n        System.out.print(\"Done \");\n    }\n}",
    "image": "",
    "option1": "Finalized Done ",
    "option2": "Done Finalized ",
    "option3": "Done (Finalized might or might not print)",
    "option4": "Compilation Error",
    "answer": 3,
    "otherInfo": "System.gc() is only a request to the JVM. Execution of GC or the finalize method is not guaranteed immediately."
  },
  {
    "id": 54,
    "question": "Which map implementation retains keys in natural sorted order or using a custom Comparator?",
    "code": "",
    "image": "",
    "option1": "LinkedHashMap",
    "option2": "TreeMap",
    "option3": "ConcurrentHashMap",
    "option4": "IdentityHashMap",
    "answer": 2,
    "otherInfo": "TreeMap implements the NavigableMap interface and sorts its keys based on natural ordering or a supplied Comparator."
  },
  {
    "id": 55,
    "question": "What will be the outcome of compiling and running this program?",
    "code": "public class InstanceOfTest {\n    public static void main(String[] args) {\n        String str = null;\n        System.out.println(str instanceof String);\n    }\n}",
    "image": "",
    "option1": "true",
    "option2": "false",
    "option3": "NullPointerException",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "The instanceof operator always evaluates to false if the left operand is null, without throwing a NullPointerException."
  },
  {
    "id": 56,
    "question": "What will be printed by the following code?",
    "code": "public class ArrayInit {\n    public static void main(String[] args) {\n        int[] arr = {10, 20, 30};\n        System.out.println(arr.getClass().getName());\n    }\n}",
    "image": "",
    "option1": "java.util.ArrayList",
    "option2": "[I",
    "option3": "int[]",
    "option4": "Array",
    "answer": 2,
    "otherInfo": "Internal JVM class representation for a single-dimensional primitive int array is '[I'."
  },
  {
    "id": 57,
    "question": "Which class is an immutable, high-precision alternative for floating-point calculations in financial applications?",
    "code": "",
    "image": "",
    "option1": "BigInteger",
    "option2": "Float",
    "option3": "Double",
    "option4": "BigDecimal",
    "answer": 4,
    "otherInfo": "BigDecimal provides precise arbitrary-precision signed decimal numbers, preventing floating-point rounding errors."
  },
  {
    "id": 58,
    "question": "What is the output of the following switch expression?",
    "code": "public class YieldTest {\n    public static void main(String[] args) {\n        String fruit = \"Apple\";\n        int code = switch (fruit) {\n            case \"Apple\", \"Pear\" -> 1;\n            case \"Banana\" -> 2;\n            default -> 0;\n        };\n        System.out.println(code);\n    }\n}",
    "image": "",
    "option1": "1",
    "option2": "2",
    "option3": "0",
    "option4": "Compilation Error",
    "answer": 1,
    "otherInfo": "Switch expressions (standardized in Java 14) allow comma-separated cases and arrow syntax without break statements."
  },
  {
    "id": 59,
    "question": "What will happen when compiling this custom checked exception class?",
    "code": "class CustomException extends Exception {\n    public CustomException(String msg) {\n        super(msg);\n    }\n}\npublic class ExceptionTest {\n    public static void main(String[] args) {\n        throw new CustomException(\"Error occurred\");\n    }\n}",
    "image": "",
    "option1": "Prints: Error occurred",
    "option2": "Compilation Error because main does not declare or handle CustomException",
    "option3": "Runtime Exception",
    "option4": "Code runs without output",
    "answer": 2,
    "otherInfo": "CustomException extends Exception, making it a checked exception. It must be caught or declared in the throws clause of main."
  },
  {
    "id": 60,
    "question": "What is the output of the following block of code?",
    "code": "public class TernaryNullTest {\n    public static void main(String[] args) {\n        boolean flag = true;\n        Integer a = null;\n        int b = flag ? a : 0;\n        System.out.println(b);\n    }\n}",
    "image": "",
    "option1": "0",
    "option2": "null",
    "option3": "NullPointerException",
    "option4": "Compilation Error",
    "answer": 3,
    "otherInfo": "The ternary expression resolves to integer type (unboxing Integer 'a' to primitive int), which throws a NullPointerException because 'a' is null."
  },
  {
    "id": 61,
    "question": "What will be the output of the following program containing bitwise shift operators?",
    "code": "public class ShiftOperatorTest {\n    public static void main(String[] args) {\n        int a = -8;\n        System.out.println((a >> 1) + \" \" + (a >>> 29));\n    }\n}",
    "image": "",
    "option1": "-4 7",
    "option2": "-4 3",
    "option3": "-4 0",
    "option4": "-4 -2",
    "answer": 1,
    "otherInfo": ">> is the signed right-shift operator (preserves sign bit), while >>> is the unsigned right-shift operator (fills top bits with 0s)."
  },
  {
    "id": 62,
    "question": "What is the output of the following try-catch-finally block when a NullPointerException is thrown?",
    "code": "public class CatchFlowTest {\n    public static void main(String[] args) {\n        try {\n            String str = null;\n            System.out.print(str.length());\n        } catch (NullPointerException e) {\n            System.out.print(\"NPE \");\n            throw new RuntimeException();\n        } catch (Exception e) {\n            System.out.print(\"EXP \");\n        } finally {\n            System.out.print(\"FIN \");\n        }\n    }\n}",
    "image": "",
    "option1": "NPE FIN followed by RuntimeException",
    "option2": "NPE EXP FIN",
    "option3": "NPE EXP",
    "option4": "Compilation Error due to rethrowing exception",
    "answer": 1,
    "otherInfo": "NPE catch runs first, prints 'NPE ', then throws RuntimeException. The finally block executes before the thread terminates abruptly with RuntimeException."
  },
  {
    "id": 63,
    "question": "What will be the output of the following inheritance and constructor initialization program?",
    "code": "class Parent {\n    Parent() {\n        System.out.print(\"Parent \");\n    }\n}\nclass Child extends Parent {\n    Child() {\n        this(10);\n        System.out.print(\"Child-NoArg \");\n    }\n    Child(int x) {\n        System.out.print(\"Child-Arg \");\n    }\n}\npublic class Test {\n    public static void main(String[] args) {\n        new Child();\n    }\n}",
    "image": "",
    "option1": "Child-Arg Child-NoArg Parent ",
    "option2": "Parent Child-NoArg Child-Arg ",
    "option3": "Parent Child-Arg Child-NoArg ",
    "option4": "Child-NoArg Child-Arg ",
    "answer": 3,
    "otherInfo": "Child() delegates to Child(10) via this(10). Child(10) implicitly calls super(), which prints 'Parent ', then 'Child-Arg ', and finally 'Child-NoArg ' executes."
  },
  {
    "id": 64,
    "question": "What is the output of the following boolean logical short-circuit evaluation?",
    "code": "public class ShortCircuitTest {\n    public static void main(String[] args) {\n        int x = 10;\n        if (++x > 10 || ++x > 20) {\n            x++;\n        }\n        System.out.println(x);\n    }\n}",
    "image": "",
    "option1": "11",
    "option2": "12",
    "option3": "13",
    "option4": "10",
    "answer": 2,
    "otherInfo": "++x makes x=11. Since 11 > 10 is true, the || short-circuits and skips ++x > 20. Then x++ executes, making x=12."
  },
  {
    "id": 65,
    "question": "What happens when compiling and executing the following program with a try-with-resources statement?",
    "code": "class MyResource implements AutoCloseable {\n    public void close() {\n        System.out.print(\"Close \");\n    }\n}\npublic class TryResourceTest {\n    public static void main(String[] args) {\n        try (MyResource r = new MyResource()) {\n            System.out.print(\"Work \");\n        }\n    }\n}",
    "image": "",
    "option1": "Work ",
    "option2": "Close Work ",
    "option3": "Work Close ",
    "option4": "Compilation Error",
    "answer": 3,
    "otherInfo": "Resources defined in try-with-resources auto-close at the end of the try block, calling close() automatically."
  },
  {
    "id": 66,
    "question": "What will be printed by the following code snippet?",
    "code": "public class CompoundAssignment {\n    public static void main(String[] args) {\n        int x = 5;\n        x += x++ + ++x;\n        System.out.println(x);\n    }\n}",
    "image": "",
    "option1": "17",
    "option2": "16",
    "option3": "18",
    "option4": "15",
    "answer": 1,
    "otherInfo": "x += (x++ + ++x) evaluates to x = 5 + (5 + 7) = 17. (x++ returns 5 and makes x=6; then ++x makes x=7 and returns 7)."
  },
  {
    "id": 67,
    "question": "Which of the following is true about abstract classes and interfaces in Java 8 and beyond?",
    "code": "",
    "image": "",
    "option1": "An abstract class can have constructors, but an interface cannot.",
    "option2": "Interfaces can maintain state with instance fields.",
    "option3": "Classes can inherit from multiple abstract classes.",
    "option4": "Abstract classes cannot contain concrete methods.",
    "answer": 1,
    "otherInfo": "Abstract classes have constructors used during subclass instantiation, whereas interfaces cannot define constructors."
  },
  {
    "id": 68,
    "question": "What will be the output of the following exception handling program?",
    "code": "public class MultiCatchTest {\n    public static void main(String[] args) {\n        try {\n            int[] arr = new int[2];\n            arr[5] = 10 / 0;\n        } catch (ArithmeticException | ArrayIndexOutOfBoundsException e) {\n            System.out.println(e.getClass().getSimpleName());\n        }\n    }\n}",
    "image": "",
    "option1": "ArrayIndexOutOfBoundsException",
    "option2": "ArithmeticException",
    "option3": "Compilation Error",
    "option4": "Exception",
    "answer": 2,
    "otherInfo": "Right-hand side expression 10 / 0 is evaluated first before assignment, triggering an ArithmeticException."
  },
  {
    "id": 69,
    "question": "What is the output of the following instance method invocation on a null variable?",
    "code": "class Helper {\n    public static void printMsg() {\n        System.out.println(\"Static Method\");\n    }\n}\npublic class Main {\n    public static void main(String[] args) {\n        Helper h = null;\n        h.printMsg();\n    }\n}",
    "image": "",
    "option1": "NullPointerException",
    "option2": "Static Method",
    "option3": "Compilation Error",
    "option4": "Undefined Behavior",
    "answer": 2,
    "otherInfo": "Static methods are resolved at compile-time using the declared type reference (Helper), so no NullPointerException occurs even if the object variable is null."
  },
  {
    "id": 70,
    "question": "What will be the output of the following string manipulation program?",
    "code": "public class StringReplaceTest {\n    public static void main(String[] args) {\n        String str = \"a.b.c\";\n        System.out.println(str.replace(\".\", \"/\") + \" \" + str.replaceAll(\".\", \"/\"));\n    }\n}",
    "image": "",
    "option1": "a/b/c a/b/c",
    "option2": "a/b/c /////",
    "option3": "a.b.c /////",
    "option4": "a/b/c a.b.c",
    "answer": 2,
    "otherInfo": "replace() treats '.' as a literal target character, whereas replaceAll() uses regex where '.' matches any character."
  },
  {
    "id": 71,
    "question": "What will happen when compiling and running this code with nested try-catch blocks?",
    "code": "public class NestedTryTest {\n    public static void main(String[] args) {\n        try {\n            try {\n                int x = 5 / 0;\n            } catch (NullPointerException e) {\n                System.out.print(\"Inner \");\n            }\n        } catch (ArithmeticException e) {\n            System.out.print(\"Outer \");\n        }\n    }\n}",
    "image": "",
    "option1": "Inner ",
    "option2": "Outer ",
    "option3": "Inner Outer ",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "The inner try throws ArithmeticException, which does not match NullPointerException, so it propagates up and gets caught by the outer catch block."
  },
  {
    "id": 72,
    "question": "Which collection class should be used when dynamic array capacity needs fast non-synchronized insertions/deletions at both ends?",
    "code": "",
    "image": "",
    "option1": "LinkedList",
    "option2": "ArrayDeque",
    "option3": "Stack",
    "option4": "Vector",
    "answer": 2,
    "otherInfo": "ArrayDeque is generally faster than Stack and LinkedList when used as a stack or double-ended queue (deque)."
  },
  {
    "id": 73,
    "question": "What will be printed by the following code?",
    "code": "public class InstanceVariableInit {\n    int a;\n    boolean b;\n    String c;\n    public static void main(String[] args) {\n        InstanceVariableInit obj = new InstanceVariableInit();\n        System.out.println(obj.a + \" \" + obj.b + \" \" + obj.c);\n    }\n}",
    "image": "",
    "option1": "0 false null",
    "option2": "0 true null",
    "option3": "garbage false null",
    "option4": "Compilation Error",
    "answer": 1,
    "otherInfo": "Instance variables get default values upon object creation (0 for numeric primitives, false for boolean, null for reference types)."
  },
  {
    "id": 74,
    "question": "What is the output of the following method overloading program with primitive types?",
    "code": "public class OverloadPrimitive {\n    static void check(long val) { System.out.println(\"long\"); }\n    static void check(double val) { System.out.println(\"double\"); }\n    public static void main(String[] args) {\n        check(10);\n    }\n}",
    "image": "",
    "option1": "double",
    "option2": "long",
    "option3": "Compilation Error",
    "option4": "ClassCastException",
    "answer": 2,
    "otherInfo": "Literal 10 is an int. The JVM picks the closest primitive widening conversion, which is long over double."
  },
  {
    "id": 75,
    "question": "Which of the following exceptions is an UNCHECKED exception in Java?",
    "code": "",
    "image": "",
    "option1": "java.io.IOException",
    "option2": "java.sql.SQLException",
    "option3": "java.lang.IllegalArgumentException",
    "option4": "java.lang.ClassNotFoundException",
    "answer": 3,
    "otherInfo": "IllegalArgumentException inherits from RuntimeException, making it an unchecked exception."
  },
  {
    "id": 76,
    "question": "What is the output of the following array clone operation?",
    "code": "public class ArrayCloneTest {\n    public static void main(String[] args) {\n        int[] original = {1, 2, 3};\n        int[] clone = original.clone();\n        System.out.println((original == clone) + \" \" + original.equals(clone));\n    }\n}",
    "image": "",
    "option1": "true true",
    "option2": "false true",
    "option3": "false false",
    "option4": "true false",
    "answer": 3,
    "otherInfo": "Array clone creates a distinct object in heap memory (== gives false). Array objects do not override equals(), so Object.equals() evaluates identity equality (==), returning false."
  },
  {
    "id": 77,
    "question": "What will be printed by the following code involving ternary operator type promotion?",
    "code": "public class TernaryTypePromotion {\n    public static void main(String[] args) {\n        Object obj = true ? new Integer(1) : new Double(2.0);\n        System.out.println(obj);\n    }\n}",
    "image": "",
    "option1": "1",
    "option2": "1.0",
    "option3": "2.0",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "When mixing numeric wrapper types in a ternary expression, unboxing and numeric promotion forces the result to double (1.0)."
  },
  {
    "id": 78,
    "question": "What is the output of the following code snippet?",
    "code": "public class DefaultConstructorTest {\n    public static void main(String[] args) {\n        class Alpha {\n            Alpha(int x) {}\n        }\n        // Alpha a = new Alpha();\n        System.out.println(\"Compiled Successfully\");\n    }\n}",
    "image": "",
    "option1": "Prints: Compiled Successfully",
    "option2": "Uncommenting line marked with // will cause a Compilation Error.",
    "option3": "Both Option 1 and Option 2 are correct.",
    "option4": "Class Alpha automatically retains its default no-arg constructor.",
    "answer": 3,
    "otherInfo": "If a developer defines any parameterized constructor in a class, Java does NOT provide a default no-arg constructor."
  },
  {
    "id": 79,
    "question": "What is the outcome of compiling and running this thread synchronization code?",
    "code": "public class SyncTest {\n    public synchronized static void printA() { System.out.print(\"A \"); }\n    public synchronized void printB() { System.out.print(\"B \"); }\n    public static void main(String[] args) {\n        SyncTest obj = new SyncTest();\n        obj.printA();\n        obj.printB();\n    }\n}",
    "image": "",
    "option1": "A B ",
    "option2": "Compilation Error",
    "option3": "Deadlock at runtime",
    "option4": "B A ",
    "answer": 1,
    "otherInfo": "synchronized static locks on the Class object (SyncTest.class), while synchronized instance method locks on the object instance (obj). Both run sequentially on the main thread without issue."
  },
  {
    "id": 80,
    "question": "Which of the following statements about `final` local variables inside lambda expressions is true?",
    "code": "",
    "image": "",
    "option1": "Local variables captured by lambda expressions must be explicitly marked final or effectively final.",
    "option2": "Lambda expressions can modify local variables declared in the enclosing scope.",
    "option3": "Local variables captured by lambdas are stored on the thread stack and modified safely.",
    "option4": "Lambdas can only access static fields of the enclosing class.",
    "answer": 1,
    "otherInfo": "Local variables referenced inside lambda expressions must be final or effectively final (value not modified after initialization)."
  },
  {
    "id": 81,
    "question": "What is the output of the following string builder operation?",
    "code": "public class SBDeleteTest {\n    public static void main(String[] args) {\n        StringBuilder sb = new StringBuilder(\"0123456789\");\n        sb.delete(3, 6);\n        System.out.println(sb);\n    }\n}",
    "image": "",
    "option1": "0126789",
    "option2": "01236789",
    "option3": "012789",
    "option4": "012346789",
    "answer": 1,
    "otherInfo": "delete(start, end) removes characters from index start (inclusive, index 3) up to end (exclusive, index 6). Indices 3, 4, 5 ('3', '4', '5') are removed."
  },
  {
    "id": 82,
    "question": "What will happen during compilation or execution of this try-catch block?",
    "code": "public class CatchOrder {\n    public static void main(String[] args) {\n        try {\n            int a = 10 / 0;\n        } catch (Exception e) {\n            System.out.print(\"Exception \");\n        } /* catch (ArithmeticException e) {\n            System.out.print(\"Arithmetic \");\n        } */\n    }\n}",
    "image": "",
    "option1": "Code runs and prints: Exception ",
    "option2": "Uncommenting the second catch block causes a Compilation Error.",
    "option3": "Uncommenting the second catch block compiles and runs cleanly.",
    "option4": "Both 1 and 2 are true.",
    "answer": 4,
    "otherInfo": "Uncommenting ArithmeticException after catching general Exception results in unreachable code compile error."
  },
  {
    "id": 83,
    "question": "Which of the following collections DOES NOT allow duplicate elements and does not guarantee any order?",
    "code": "",
    "image": "",
    "option1": "TreeSet",
    "option2": "LinkedHashSet",
    "option3": "HashSet",
    "option4": "ArrayList",
    "answer": 3,
    "otherInfo": "HashSet stores unique elements backed by a hash table with no guarantees on ordering."
  },
  {
    "id": 84,
    "question": "What is the output of the following increment/decrement operator code?",
    "code": "public class OperatorMix {\n    public static void main(String[] args) {\n        int i = 1;\n        i = i++ + ++i * --i;\n        System.out.println(i);\n    }\n}",
    "image": "",
    "option1": "7",
    "option2": "6",
    "option3": "8",
    "option4": "5",
    "answer": 1,
    "otherInfo": "i++ returns 1 (i becomes 2). ++i makes i 3 and returns 3. --i makes i 2 and returns 2. So expression is 1 + (3 * 2) = 7."
  },
  {
    "id": 85,
    "question": "What will be printed by the following code snippet?",
    "code": "public class LabelledLoopTest {\n    public static void main(String[] args) {\n        int count = 0;\n        row:\n        for (int i = 0; i < 2; i++) {\n            col:\n            for (int j = 0; j < 2; j++) {\n                if (i == j) continue row;\n                count++;\n            }\n        }\n        System.out.println(count);\n    }\n}",
    "image": "",
    "option1": "0",
    "option2": "1",
    "option3": "2",
    "option4": "4",
    "answer": 1,
    "otherInfo": "When i=0, j=0 (i==j is true), `continue row` jumps to next iteration of outer loop (i=1). When i=1, j=0 (i!=j), count becomes 1. When i=1, j=1, `continue row` ends loop. Total count = 0."
  },
  {
    "id": 86,
    "question": "What is the result of attempting to access a non-static variable inside a static context?",
    "code": "public class StaticContextTest {\n    int num = 100;\n    public static void main(String[] args) {\n        // System.out.println(num);\n    }\n}",
    "image": "",
    "option1": "Prints: 100",
    "option2": "Prints: 0",
    "option3": "Compilation Error: Non-static variable num cannot be referenced from a static context",
    "option4": "Runtime Exception",
    "answer": 3,
    "otherInfo": "Static methods belong to the class level and exist before any object instance is created; thus instance variables cannot be directly accessed without an object reference."
  },
  {
    "id": 87,
    "question": "Which interface should be extended to create a custom unchecked exception in Java?",
    "code": "",
    "image": "",
    "option1": "java.lang.Throwable",
    "option2": "java.lang.Exception",
    "option3": "java.lang.RuntimeException",
    "option4": "java.lang.Error",
    "answer": 3,
    "otherInfo": "Inheriting from RuntimeException creates a custom unchecked exception (compiler does not require catch or throws clause)."
  },
  {
    "id": 88,
    "question": "What is the output of the following array comparison program?",
    "code": "import java.util.Arrays;\npublic class ArrayEqualsTest {\n    public static void main(String[] args) {\n        int[] a1 = {1, 2, 3};\n        int[] a2 = {1, 2, 3};\n        System.out.println(a1.equals(a2) + \" \" + Arrays.equals(a1, a2));\n    }\n}",
    "image": "",
    "option1": "true true",
    "option2": "false true",
    "option3": "true false",
    "option4": "false false",
    "answer": 2,
    "otherInfo": "a1.equals(a2) performs reference equality (false). Arrays.equals(a1, a2) compares the actual contents of both arrays (true)."
  },
  {
    "id": 89,
    "question": "What will be printed when running the following program?",
    "code": "public class SuperFieldTest {\n    public static void main(String[] args) {\n        SubClass obj = new SubClass();\n        obj.display();\n    }\n}\nclass SuperClass {\n    int num = 10;\n}\nclass SubClass extends SuperClass {\n    int num = 20;\n    void display() {\n        System.out.println(num + \" \" + super.num);\n    }\n}",
    "image": "",
    "option1": "20 20",
    "option2": "10 20",
    "option3": "20 10",
    "option4": "Compilation Error",
    "answer": 3,
    "otherInfo": "num refers to the subclass field (20), while super.num refers to the field inherited from SuperClass (10)."
  },
  {
    "id": 90,
    "question": "What will be the output of the following switch statement using char data type?",
    "code": "public class CharSwitch {\n    public static void main(String[] args) {\n        char ch = 'B';\n        switch (ch) {\n            case 'A': System.out.print(\"A \"); break;\n            case 'B': System.out.print(\"B \");\n            case 'C': System.out.print(\"C \"); break;\n            default: System.out.print(\"D \");\n        }\n    }\n}",
    "image": "",
    "option1": "B ",
    "option2": "B C ",
    "option3": "B C D ",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "Matches case 'B', prints 'B '. Since there is no break statement at case 'B', execution falls through to case 'C', prints 'C ', and then hits the break."
  },
  {
    "id": 91,
    "question": "What will be the output of the following program containing post-increment and assignment operations?",
    "code": "public class IncrementTest {\n    public static void main(String[] args) {\n        int i = 0;\n        for (int j = 0; j < 5; j++) {\n            i = i++;\n        }\n        System.out.println(i);\n    }\n}",
    "image": "",
    "option1": "5",
    "option2": "0",
    "option3": "4",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "In 'i = i++', the expression evaluates to the old value of i (0). Post-increment raises i to 1 in temporary memory, but the assignment overwrites i back to 0 immediately."
  },
  {
    "id": 92,
    "question": "What is the output of the following try-catch-finally block when System.exit() is NOT executed?",
    "code": "public class FinallyReturnTest {\n    public static int getNumber() {\n        try {\n            return 10;\n        } finally {\n            System.out.print(\"Finally \");\n        }\n    }\n    public static void main(String[] args) {\n        System.out.println(getNumber());\n    }\n}",
    "image": "",
    "option1": "10 Finally",
    "option2": "Finally 10",
    "option3": "10",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "The try block prepares to return 10, but execution yields control to the finally block first, which prints 'Finally '. Afterward, 10 is returned."
  },
  {
    "id": 93,
    "question": "What will happen when compiling and executing the following inheritance program with instance fields?",
    "code": "class Parent {\n    int x = 100;\n}\nclass Child extends Parent {\n    int x = 200;\n}\npublic class FieldTest {\n    public static void main(String[] args) {\n        Parent p = new Child();\n        System.out.println(p.x);\n    }\n}",
    "image": "",
    "option1": "200",
    "option2": "100",
    "option3": "Compilation Error",
    "option4": "Runtime Exception",
    "answer": 2,
    "otherInfo": "Variables/fields in Java do NOT undergo dynamic polymorphism or overriding. Field access is resolved at compile time based on the reference type (Parent)."
  },
  {
    "id": 94,
    "question": "What is the output of the following floating-point division and modulus operations?",
    "code": "public class ModulusTest {\n    public static void main(String[] args) {\n        double a = 10.0 / 0.0;\n        double b = 10.0 % 0.0;\n        System.out.println(a + \" \" + b);\n    }\n}",
    "image": "",
    "option1": "ArithmeticException ArithmeticException",
    "option2": "Infinity NaN",
    "option3": "Infinity ArithmeticException",
    "option4": "NaN Infinity",
    "answer": 2,
    "otherInfo": "Floating-point operations do not throw ArithmeticException for division/modulus by zero. 10.0 / 0.0 gives Double.POSITIVE_INFINITY and 10.0 % 0.0 gives Double.NaN."
  },
  {
    "id": 95,
    "question": "What will be printed when comparing two String instances created with double quotes vs concat()?",
    "code": "public class StringConcatPool {\n    public static void main(String[] args) {\n        String s1 = \"Java\";\n        String s2 = \"Ja\" + \"va\";\n        String s3 = \"Ja\".concat(\"va\");\n        System.out.println((s1 == s2) + \" \" + (s1 == s3));\n    }\n}",
    "image": "",
    "option1": "true true",
    "option2": "false false",
    "option3": "true false",
    "option4": "false true",
    "answer": 3,
    "otherInfo": "Compile-time constant expressions ('Ja' + 'va') are optimized into the String Constant Pool (s1 == s2 is true). Method calls like concat() create new Heap objects at runtime (s1 == s3 is false)."
  },
  {
    "id": 96,
    "question": "What is the result of running the main method on an array with null references?",
    "code": "public class ArrayNullElement {\n    public static void main(String[] args) {\n        String[] strArr = new String[3];\n        for (String s : strArr) {\n            System.out.print(s + \" \");\n        }\n    }\n}",
    "image": "",
    "option1": "null null null ",
    "option2": "   ",
    "option3": "NullPointerException",
    "option4": "Compilation Error",
    "answer": 1,
    "otherInfo": "An array of reference objects is initialized with default reference values, which are 'null'. Printing null directly outputs the word 'null'."
  },
  {
    "id": 97,
    "question": "What will be the output of the following overriding program involving exception throwing?",
    "code": "import java.io.*;\nclass Parent {\n    void execute() throws IOException {\n        System.out.print(\"Parent \");\n    }\n}\nclass Child extends Parent {\n    void execute() {\n        System.out.print(\"Child \");\n    }\n}\npublic class ExceptionOverride {\n    public static void main(String[] args) throws IOException {\n        Parent p = new Child();\n        p.execute();\n    }\n}",
    "image": "",
    "option1": "Compilation Error",
    "option2": "Child ",
    "option3": "Parent ",
    "option4": "Uncaught IOException",
    "answer": 2,
    "otherInfo": "An overriding method in a subclass can declare fewer (or no) checked exceptions than the superclass method, making this completely valid Java code."
  },
  {
    "id": 98,
    "question": "What is the output of the following initialization order code?",
    "code": "class Base {\n    static {\n        System.out.print(\"S1 \");\n    }\n    Base() {\n        System.out.print(\"C1 \");\n    }\n}\nclass Derived extends Base {\n    static {\n        System.out.print(\"S2 \");\n    }\n    Derived() {\n        System.out.print(\"C2 \");\n    }\n}\npublic class InitOrder {\n    public static void main(String[] args) {\n        new Derived();\n    }\n}",
    "image": "",
    "option1": "S1 S2 C1 C2 ",
    "option2": "S1 C1 S2 C2 ",
    "option3": "C1 C2 S1 S2 ",
    "option4": "S2 S1 C2 C1 ",
    "answer": 1,
    "otherInfo": "Static blocks run in parent-then-child order during class loading (S1 S2). Constructor execution then flows parent-first then child-second (C1 C2)."
  },
  {
    "id": 99,
    "question": "What happens when using list removal operations inside an enhanced for-loop?",
    "code": "import java.util.*;\npublic class CollectionRemove {\n    public static void main(String[] args) {\n        List<String> list = new ArrayList<>(Arrays.asList(\"A\", \"B\", \"C\"));\n        for (String item : list) {\n            if (\"B\".equals(item)) {\n                list.remove(item);\n            }\n        }\n    }\n}",
    "image": "",
    "option1": "Compiles and executes without error",
    "option2": "ConcurrentModificationException",
    "option3": "IndexOutOfBoundsException",
    "option4": "UnsupportedOperationException",
    "answer": 2,
    "otherInfo": "Modifying an ArrayList directly while iterating using an enhanced for-loop disrupts the underlying iterator's expected modCount, raising a ConcurrentModificationException."
  },
  {
    "id": 100,
    "question": "What is the output of the following compound ternary condition?",
    "code": "public class TernaryLogic {\n    public static void main(String[] args) {\n        boolean a = true;\n        boolean b = false;\n        int res = a ? (b ? 1 : 2) : 3;\n        System.out.println(res);\n    }\n}",
    "image": "",
    "option1": "1",
    "option2": "2",
    "option3": "3",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "Since 'a' is true, the outer condition resolves to the first branch: (b ? 1 : 2). Because 'b' is false, it returns 2."
  },
  {
    "id": 101,
    "question": "What is the default capacity growth formula for standard ArrayList when capacity is exceeded?",
    "code": "",
    "image": "",
    "option1": "Doubles the capacity (oldCapacity * 2)",
    "option2": "Increases by 50% (oldCapacity + (oldCapacity >> 1))",
    "option3": "Increases by 10 elements statically",
    "option4": "Triples the capacity (oldCapacity * 3)",
    "answer": 2,
    "otherInfo": "In OpenJDK implementation, an ArrayList grows its inner storage array by 50% of its current size when full (newCapacity = oldCapacity + (oldCapacity >> 1))."
  },
  {
    "id": 102,
    "question": "What will be printed when passing an array into a method and mutating an element?",
    "code": "public class PassByValueTest {\n    static void modify(int[] arr) {\n        arr[0] = 99;\n        arr = new int[]{100, 200};\n    }\n    public static void main(String[] args) {\n        int[] nums = {1, 2, 3};\n        modify(nums);\n        System.out.println(nums[0]);\n    }\n}",
    "image": "",
    "option1": "1",
    "option2": "99",
    "option3": "100",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "Java is pass-by-value. The reference copy allows mutating array contents (arr[0] = 99). Reassigning 'arr' inside modify() changes only the local parameter reference."
  },
  {
    "id": 103,
    "question": "What is the output of the following character addition and string concatenation?",
    "code": "public class CharConcatTest {\n    public static void main(String[] args) {\n        char c1 = 'A'; // ASCII 65\n        char c2 = 'B'; // ASCII 66\n        System.out.println(c1 + c2 + \" \" + c1 + c2);\n    }\n}",
    "image": "",
    "option1": "AB AB",
    "option2": "131 AB",
    "option3": "131 A B",
    "option4": "AB 131",
    "answer": 2,
    "otherInfo": "c1 + c2 performs numeric primitive addition (65 + 66 = 131). Adding \" \" turns subsequent operations into string concatenation, producing '131 AB'."
  },
  {
    "id": 104,
    "question": "Which statement accurately describes the main method signature in Java?",
    "code": "public static void main(String... args)",
    "image": "",
    "option1": "It is invalid because varargs cannot be used in main.",
    "option2": "It is valid and acts as a standard entry point for execution.",
    "option3": "It compiles but JVM fails to locate it as an entry point.",
    "option4": "It requires public static final access modifiers.",
    "answer": 2,
    "otherInfo": "The JVM recognizes `String... args` as equivalent to `String[] args` for the main entry point parameter."
  },
  {
    "id": 105,
    "question": "What will happen when compiling and running the following thread start method override?",
    "code": "class CustomThread extends Thread {\n    @Override\n    public void start() {\n        System.out.print(\"CustomStart \");\n    }\n    @Override\n    public void run() {\n        System.out.print(\"CustomRun \");\n    }\n}\npublic class OverrideStart {\n    public static void main(String[] args) {\n        CustomThread t = new CustomThread();\n        t.start();\n    }\n}",
    "image": "",
    "option1": "CustomStart CustomRun ",
    "option2": "CustomRun ",
    "option3": "CustomStart ",
    "option4": "IllegalThreadStateException",
    "answer": 3,
    "otherInfo": "Overriding start() prevents calling super.start(), so no new native OS thread is created and run() is never called automatically."
  },
  {
    "id": 106,
    "question": "What will be the output of the following nested method calls?",
    "code": "public class MethodCascade {\n    int val = 10;\n    public MethodCascade add(int x) {\n        this.val += x;\n        return this;\n    }\n    public static void main(String[] args) {\n        MethodCascade obj = new MethodCascade();\n        System.out.println(obj.add(5).add(10).val);\n    }\n}",
    "image": "",
    "option1": "15",
    "option2": "25",
    "option3": "10",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "Method chaining allows consecutive invocations on the returned 'this' reference: 10 + 5 + 10 = 25."
  },
  {
    "id": 107,
    "question": "Which of the following exceptions is thrown when a application attempts to allocate memory, but the JVM has run out of heap memory?",
    "code": "",
    "image": "",
    "option1": "java.lang.StackOverflowError",
    "option2": "java.lang.OutOfMemoryError",
    "option3": "java.lang.MemoryLimitExceededException",
    "option4": "java.lang.NullPointerException",
    "answer": 2,
    "otherInfo": "OutOfMemoryError (a subclass of java.lang.Error) is thrown by the JVM when heap memory is completely exhausted."
  },
  {
    "id": 108,
    "question": "What will be the output of the following boolean equality check?",
    "code": "public class BooleanEquals {\n    public static void main(String[] args) {\n        Boolean b1 = new Boolean(\"true\");\n        Boolean b2 = new Boolean(\"TrUe\");\n        Boolean b3 = new Boolean(\"OK\");\n        System.out.println((b1 == b2) + \" \" + b1.equals(b2) + \" \" + b3);\n    }\n}",
    "image": "",
    "option1": "false true false",
    "option2": "true true false",
    "option3": "false true null",
    "option4": "false false false",
    "answer": 1,
    "otherInfo": "Boolean constructor parses strings case-insensitively ('true' yields true; any other value yields false). 'new Boolean()' creates separate heap objects (b1 == b2 is false)."
  },
  {
    "id": 109,
    "question": "What is the output of the following abstract class and interface default method collision code?",
    "code": "interface Inter {\n    default void show() { System.out.print(\"Inter \"); }\n}\nabstract class Abs {\n    public void show() { System.out.print(\"Abs \"); }\n}\nclass Concrete extends Abs implements Inter {}\npublic class ClassWinsTest {\n    public static void main(String[] args) {\n        new Concrete().show();\n    }\n}",
    "image": "",
    "option1": "Inter ",
    "option2": "Abs ",
    "option3": "Compilation Error due to duplicate methods",
    "option4": "Runtime Exception",
    "answer": 2,
    "otherInfo": "The 'Class Wins' rule in Java states that superclass method implementation always takes priority over interface default methods."
  },
  {
    "id": 110,
    "question": "What happens when you compile and execute the following loop program?",
    "code": "public class UnreachableLoop {\n    public static void main(String[] args) {\n        final boolean flag = false;\n        while (flag) {\n            System.out.println(\"Inside Loop\");\n        }\n        System.out.println(\"Outside Loop\");\n    }\n}",
    "image": "",
    "option1": "Compilation Error: Unreachable code inside while loop",
    "option2": "Prints: Outside Loop",
    "option3": "Prints: Inside Loop Outside Loop",
    "option4": "Infinite loop",
    "answer": 2,
    "otherInfo": "Unlike unreachable statements after a return/break, conditional statements with compile-time false expressions in `while(false)` are permitted and skipped by the compiler."
  },
  {
    "id": 111,
    "question": "Which collection map implementation maintains elements ordered by access frequency (LRU behavior when configured)?",
    "code": "",
    "image": "",
    "option1": "TreeMap",
    "option2": "LinkedHashMap",
    "option3": "HashMap",
    "option4": "ConcurrentHashMap",
    "answer": 2,
    "otherInfo": "LinkedHashMap provides a special constructor `LinkedHashMap(capacity, loadFactor, accessOrder)` that maintains elements in access order when `accessOrder` is true."
  },
  {
    "id": 112,
    "question": "What is the output of the following code involving primitive type promotion in unary operators?",
    "code": "public class BytePromotion {\n    public static void main(String[] args) {\n        byte b = 10;\n        b = (byte) -b;\n        System.out.println(b);\n    }\n}",
    "image": "",
    "option1": "-10",
    "option2": "10",
    "option3": "Compilation Error without explicit casting",
    "option4": "Runtime Exception",
    "answer": 1,
    "otherInfo": "Unary minus `-b` promotes byte operand to int (-10). Explicit cast `(byte)` correctly converts it back to byte -10."
  },
  {
    "id": 113,
    "question": "What is the result of attempting to catch Error subclasses explicitly?",
    "code": "public class ErrorCatchTest {\n    public static void main(String[] args) {\n        try {\n            throw new StackOverflowError();\n        } catch (Throwable t) {\n            System.out.print(\"Caught \");\n        }\n    }\n}",
    "image": "",
    "option1": "Compilation Error",
    "option2": "Prints: Caught ",
    "option3": "Program crashes abruptly",
    "option4": "ClassCastException",
    "answer": 2,
    "otherInfo": "Errors inherit from java.lang.Throwable. While catching Error/Throwable is generally bad practice in production, Java allows catching them via try-catch."
  },
  {
    "id": 114,
    "question": "What will be printed by the following string replace method?",
    "code": "public class StringSubstrTest {\n    public static void main(String[] args) {\n        String s = \"Programming\";\n        System.out.println(s.substring(3, 3).isEmpty());\n    }\n}",
    "image": "",
    "option1": "false",
    "option2": "true",
    "option3": "StringIndexOutOfBoundsException",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "substring(beginIndex, endIndex) with identical index arguments (3, 3) yields an empty string `\"\"`, so `isEmpty()` returns true."
  },
  {
    "id": 115,
    "question": "What is the outcome of compiling and running this anonymous inner class program?",
    "code": "interface Message {\n    void print();\n}\npublic class AnonTest {\n    public static void main(String[] args) {\n        Message m = new Message() {\n            public void print() {\n                System.out.print(\"Anon \");\n            }\n        };\n        m.print();\n    }\n}",
    "image": "",
    "option1": "Anon ",
    "option2": "Compilation Error",
    "option3": "Runtime Exception",
    "option4": "NullPointerException",
    "answer": 1,
    "otherInfo": "Anonymous inner classes implement interfaces on the fly by supplying bodies for abstract methods."
  },
  {
    "id": 116,
    "question": "Which of the following statements about Java static nested classes is true?",
    "code": "",
    "image": "",
    "option1": "A static nested class can directly access instance variables of its outer class.",
    "option2": "A static nested class requires an outer class instance to be instantiated.",
    "option3": "A static nested class can be instantiated without instantiating the outer class.",
    "option4": "A static nested class cannot contain static methods.",
    "answer": 3,
    "otherInfo": "Static nested classes do not hold an implicit reference to an instance of the outer class and can be created directly: `Outer.Nested obj = new Outer.Nested();`."
  },
  {
    "id": 117,
    "question": "What is the output of the following arithmetic with wrapper null objects?",
    "code": "public class NullWrapper {\n    public static void main(String[] args) {\n        Integer num = null;\n        int val = 5;\n        System.out.println(val + num);\n    }\n}",
    "image": "",
    "option1": "5",
    "option2": "5null",
    "option3": "NullPointerException",
    "option4": "Compilation Error",
    "answer": 3,
    "otherInfo": "Adding primitive int 'val' and Wrapper 'num' forces auto-unboxing of 'num' via `num.intValue()`, causing a NullPointerException at runtime."
  },
  {
    "id": 118,
    "question": "What is the output of the following switch expression matching char primitive values?",
    "code": "public class SwitchCharTest {\n    public static void main(String[] args) {\n        int x = 65;\n        switch (x) {\n            case 'A': System.out.print(\"CharA \");\n            case 66: System.out.print(\"Num66 \"); break;\n            default: System.out.print(\"Def \");\n        }\n    }\n}",
    "image": "",
    "option1": "CharA ",
    "option2": "CharA Num66 ",
    "option3": "Num66 ",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "Character literal 'A' implicitly promotes to numeric 65. The switch matches x = 65 and falls through to print 'CharA Num66 '."
  },
  {
    "id": 119,
    "question": "What is the main difference between fail-fast and fail-safe iterators?",
    "code": "",
    "image": "",
    "option1": "Fail-fast iterators modify the collection directly; fail-safe iterators lock the collection.",
    "option2": "Fail-fast iterators throw ConcurrentModificationException on modification; fail-safe iterators work on a clone/copy of the collection.",
    "option3": "Fail-fast iterators are thread-safe; fail-safe iterators are single-threaded.",
    "option4": "There is no functional difference in Java collections.",
    "answer": 2,
    "otherInfo": "Fail-fast iterators (e.g. ArrayList iterator) throw ConcurrentModificationException when structure changes during traversal, whereas fail-safe iterators (e.g. CopyOnWriteArrayList) operate on a snapshot copy."
  },
  {
    "id": 120,
    "question": "What will be printed when calling default constructor on an array object?",
    "code": "public class ObjectArrayInit {\n    public static void main(String[] args) {\n        Object[] objArr = new String[2];\n        objArr[0] = \"Java\";\n        objArr[1] = 100;\n        System.out.println(objArr[0]);\n    }\n}",
    "image": "",
    "option1": "Java",
    "option2": "ArrayStoreException",
    "option3": "ClassCastException",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "At runtime, the array object is instantiated as `String[]`. Inserting an Integer (`100`) triggers an ArrayStoreException because an integer is not a String."
  },
  {
    "id": 121,
    "question": "What will be the output of the following simple assignment code?",
    "code": "public class OctalTest {\n    public static void main(String[] args) {\n        int x = 010;\n        System.out.println(x);\n    }\n}",
    "image": "",
    "option1": "10",
    "option2": "8",
    "option3": "0",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "In Java, integer literals starting with a leading 0 are treated as octal numbers. Octal 010 equals decimal 8."
  },
  {
    "id": 122,
    "question": "What will be printed by this string comparison program?",
    "code": "public class StringEqTest {\n    public static void main(String[] args) {\n        String s1 = \"Hello\";\n        String s2 = \"Hello\";\n        s1.toUpperCase();\n        System.out.println((s1 == s2) + \" \" + s1);\n    }\n}",
    "image": "",
    "option1": "true HELLO",
    "option2": "true Hello",
    "option3": "false Hello",
    "option4": "false HELLO",
    "answer": 2,
    "otherInfo": "Strings are immutable. s1.toUpperCase() creates a new string but doesn't modify s1. s1 and s2 still refer to the same object in String Pool."
  },
  {
    "id": 123,
    "question": "What will be the output of this loop with a missing body control?",
    "code": "public class LoopTrick {\n    public static void main(String[] args) {\n        int i = 0;\n        for (i = 0; i < 5; i++);\n        System.out.println(i);\n    }\n}",
    "image": "",
    "option1": "0",
    "option2": "4",
    "option3": "5",
    "option4": "Compilation Error",
    "answer": 3,
    "otherInfo": "The semicolon right after the for statement makes it an empty loop. The loop runs until i becomes 5, then exits and prints 5."
  },
  {
    "id": 124,
    "question": "What will happen when you try to compile and run this class with multiple public classes?",
    "code": "// Saved in file named Test.java\npublic class Test {}\npublic class Demo {}",
    "image": "",
    "option1": "Compiles successfully into Test.class",
    "option2": "Compilation Error: class Demo is public, should be declared in a file named Demo.java",
    "option3": "Runs without errors",
    "option4": "Runtime Exception",
    "answer": 2,
    "otherInfo": "A Java source file can contain at most one public top-level class, and its name must match the source file name."
  },
  {
    "id": 125,
    "question": "What will be the output of the following arithmetic with characters?",
    "code": "public class CharArith {\n    public static void main(String[] args) {\n        char ch = 'A';\n        ch++;\n        System.out.println(ch);\n    }\n}",
    "image": "",
    "option1": "A",
    "option2": "B",
    "option3": "66",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "Increment/decrement operators automatically perform implicit casting. 'A' (65) incremented becomes 'B' (66)."
  },
  {
    "id": 126,
    "question": "What will be the output when executing the following try-catch block?",
    "code": "public class CatchAll {\n    public static void main(String[] args) {\n        try {\n            int x = 5 / 0;\n        } catch (Throwable t) {\n            System.out.println(\"Handled\");\n        }\n    }\n}",
    "image": "",
    "option1": "Handled",
    "option2": "Compilation Error",
    "option3": "ArithmeticException unhandled",
    "option4": "NullPointerException",
    "answer": 1,
    "otherInfo": "Throwable is the superclass of Exception and Error, so catching Throwable handles ArithmeticException successfully."
  },
  {
    "id": 127,
    "question": "What will be printed when creating a zero-length array?",
    "code": "public class ZeroArray {\n    public static void main(String[] args) {\n        int[] arr = new int[0];\n        System.out.println(arr.length);\n    }\n}",
    "image": "",
    "option1": "0",
    "option2": "NegativeArraySizeException",
    "option3": "Compilation Error",
    "option4": "NullPointerException",
    "answer": 1,
    "otherInfo": "Arrays of size 0 are completely valid in Java, and accessing length returns 0."
  },
  {
    "id": 128,
    "question": "What is the result of checking equality between Double and Integer wrapper objects?",
    "code": "public class WrapperEq {\n    public static void main(String[] args) {\n        Integer i = 10;\n        Double d = 10.0;\n        // System.out.println(i == d);\n    }\n}",
    "image": "",
    "option1": "Prints: true",
    "option2": "Prints: false",
    "option3": "Compilation Error: incomparable types: Integer and Double",
    "option4": "Runtime Exception",
    "answer": 3,
    "otherInfo": "The '==' operator cannot be applied to references of two completely unrelated wrapper classes."
  },
  {
    "id": 129,
    "question": "What will be the output of the following boolean evaluation?",
    "code": "public class BoolAssign {\n    public static void main(String[] args) {\n        boolean b = false;\n        if (b = true) {\n            System.out.println(\"YES\");\n        } else {\n            System.out.println(\"NO\");\n        }\n    }\n}",
    "image": "",
    "option1": "NO",
    "option2": "YES",
    "option3": "Compilation Error",
    "option4": "Runtime Exception",
    "answer": 2,
    "otherInfo": "'b = true' is an assignment, not a comparison. It assigns true to b and evaluates to true inside the if condition."
  },
  {
    "id": 130,
    "question": "Which statement about standard Java main method overload is correct?",
    "code": "public class MainOverload {\n    public static void main(String[] args) {\n        System.out.print(\"Main1 \");\n        main(\"Test\");\n    }\n    public static void main(String arg) {\n        System.out.print(\"Main2 \");\n    }\n}",
    "image": "",
    "option1": "Compilation Error",
    "option2": "Prints: Main1 Main2 ",
    "option3": "Prints: Main1 ",
    "option4": "Runtime Exception",
    "answer": 2,
    "otherInfo": "The main method can be overloaded just like any other static method. The JVM only calls main(String[] args) initially."
  },
  {
    "id": 131,
    "question": "What is the output of modifying a string inside a method?",
    "code": "public class StringPass {\n    static void change(String s) {\n        s = \"World\";\n    }\n    public static void main(String[] args) {\n        String str = \"Hello\";\n        change(str);\n        System.out.println(str);\n    }\n}",
    "image": "",
    "option1": "Hello",
    "option2": "World",
    "option3": "HelloWorld",
    "option4": "Compilation Error",
    "answer": 1,
    "otherInfo": "Java passes reference variables by value. Reassigning 's' inside change() does not affect 'str' in the caller."
  },
  {
    "id": 132,
    "question": "What will be printed when adding elements into a HashSet?",
    "code": "import java.util.*;\npublic class SetAdd {\n    public static void main(String[] args) {\n        Set<String> set = new HashSet<>();\n        System.out.print(set.add(\"A\") + \" \");\n        System.out.print(set.add(\"A\"));\n    }\n}",
    "image": "",
    "option1": "true true",
    "option2": "true false",
    "option3": "false false",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "HashSet.add() returns true if the element was added successfully and false if the element already exists."
  },
  {
    "id": 133,
    "question": "What is the output of the following print statement containing null?",
    "code": "public class NullPrint {\n    public static void main(String[] args) {\n        String s = null;\n        System.out.println(\"Val: \" + s);\n    }\n}",
    "image": "",
    "option1": "Val: ",
    "option2": "Val: null",
    "option3": "NullPointerException",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "String concatenation automatically converts null references into the string \"null\"."
  },
  {
    "id": 134,
    "question": "What is the output of integer division before assignment to double?",
    "code": "public class DivCast {\n    public static void main(String[] args) {\n        double d = 1 / 2;\n        System.out.println(d);\n    }\n}",
    "image": "",
    "option1": "0.5",
    "option2": "0.0",
    "option3": "0",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "1 / 2 performs integer division resulting in 0. Assigning 0 to double implicitly converts it to 0.0."
  },
  {
    "id": 135,
    "question": "What happens when you declare a method as abstract and final simultaneously?",
    "code": "abstract class Demo {\n    // abstract final void test();\n}",
    "image": "",
    "option1": "Allowed; requires child class implementation.",
    "option2": "Compilation Error: illegal combination of modifiers: abstract and final",
    "option3": "Runtime Exception",
    "option4": "Allowed; method cannot be overridden.",
    "answer": 2,
    "otherInfo": "abstract requires child classes to override the method, while final forbids overriding. They are illegal together."
  },
  {
    "id": 136,
    "question": "What is the output of the following method overload with String and Object parameters?",
    "code": "public class OverloadAmbiguity {\n    static void test(Object o) { System.out.print(\"Object \"); }\n    static void test(String s) { System.out.print(\"String \"); }\n    public static void main(String[] args) {\n        test(null);\n    }\n}",
    "image": "",
    "option1": "Object ",
    "option2": "String ",
    "option3": "Compilation Error due to ambiguity",
    "option4": "NullPointerException",
    "answer": 2,
    "otherInfo": "The compiler always chooses the most specific method. String is a subclass of Object, so String is more specific."
  },
  {
    "id": 137,
    "question": "What will be printed when accessing an element out of array bounds in a try block?",
    "code": "public class ArrayEx {\n    public static void main(String[] args) {\n        try {\n            int[] a = {1, 2};\n            System.out.print(a[2] + \" \");\n        } catch (ArrayIndexOutOfBoundsException e) {\n            System.out.print(\"Out \");\n        } finally {\n            System.out.print(\"Fin\");\n        }\n    }\n}",
    "image": "",
    "option1": "Out Fin",
    "option2": "Fin",
    "option3": "Out",
    "option4": "ArrayIndexOutOfBoundsException",
    "answer": 1,
    "otherInfo": "a[2] throws ArrayIndexOutOfBoundsException, caught by the catch block (prints 'Out '), then finally executes (prints 'Fin')."
  },
  {
    "id": 138,
    "question": "What will be the output of the following program?",
    "code": "public class LoopSkip {\n    public static void main(String[] args) {\n        int x = 0;\n        while (x < 3) {\n            x++;\n            if (x == 2) continue;\n            System.out.print(x + \" \");\n        }\n    }\n}",
    "image": "",
    "option1": "1 2 3 ",
    "option2": "1 3 ",
    "option3": "1 2 ",
    "option4": "2 3 ",
    "answer": 2,
    "otherInfo": "When x becomes 2, continue skips printing. Values 1 and 3 are printed."
  },
  {
    "id": 139,
    "question": "Which of the following default values is given to local primitive variables in Java?",
    "code": "",
    "image": "",
    "option1": "0",
    "option2": "null",
    "option3": "Garbage value",
    "option4": "No default value; must be explicitly initialized before use.",
    "answer": 4,
    "otherInfo": "Local variables in Java are stored on the stack and do NOT receive default values. Using uninitialized local variables causes compilation error."
  },
  {
    "id": 140,
    "question": "What will be printed when operating on a empty Stack?",
    "code": "import java.util.Stack;\npublic class StackTest {\n    public static void main(String[] args) {\n        Stack<Integer> st = new Stack<>();\n        System.out.println(st.empty());\n    }\n}",
    "image": "",
    "option1": "true",
    "option2": "false",
    "option3": "EmptyStackException",
    "option4": "Compilation Error",
    "answer": 1,
    "otherInfo": "Stack.empty() returns true when the stack contains no elements."
  },
  {
    "id": 141,
    "question": "What is the output of the following program with super keyword?",
    "code": "class Parent {\n    String name = \"Parent\";\n}\nclass Child extends Parent {\n    String name = \"Child\";\n    void print() {\n        System.out.println(super.name);\n    }\n}\npublic class SuperTest {\n    public static void main(String[] args) {\n        new Child().print();\n    }\n}",
    "image": "",
    "option1": "Child",
    "option2": "Parent",
    "option3": "null",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "super.name explicitly targets the variable 'name' defined in Parent class."
  },
  {
    "id": 142,
    "question": "What will happen if the main method is declared private?",
    "code": "public class PrivateMain {\n    private static void main(String[] args) {\n        System.out.println(\"Hello\");\n    }\n}",
    "image": "",
    "option1": "Compiles and prints Hello",
    "option2": "Compilation Error",
    "option3": "Compiles, but throws 'Main method not found / not public' at runtime",
    "option4": "Runs with warning",
    "answer": 3,
    "otherInfo": "The Java compiler compiles private main cleanly, but JVM cannot execute it because main must be public."
  },
  {
    "id": 143,
    "question": "What will be printed by the following ternary expression?",
    "code": "public class TernaryShort {\n    public static void main(String[] args) {\n        int x = 10;\n        int y = (x > 5) ? 1 : 2;\n        System.out.println(y);\n    }\n}",
    "image": "",
    "option1": "10",
    "option2": "1",
    "option3": "2",
    "option4": "5",
    "answer": 2,
    "otherInfo": "(10 > 5) is true, so the first expression 1 is assigned to y."
  },
  {
    "id": 144,
    "question": "What will be the output of length on string array vs string object?",
    "code": "public class LengthCheck {\n    public static void main(String[] args) {\n        String[] arr = {\"Java\"};\n        String s = \"Java\";\n        System.out.println(arr.length + \" \" + s.length());\n    }\n}",
    "image": "",
    "option1": "1 4",
    "option2": "4 4",
    "option3": "1 1",
    "option4": "4 1",
    "answer": 1,
    "otherInfo": "arr.length is an array property (1 element), while s.length() is a String method returning character count (4)."
  },
  {
    "id": 145,
    "question": "What is the output when creating two Thread objects without starting them?",
    "code": "public class ThreadState {\n    public static void main(String[] args) {\n        Thread t = new Thread();\n        System.out.println(t.getState());\n    }\n}",
    "image": "",
    "option1": "RUNNABLE",
    "option2": "NEW",
    "option3": "WAITING",
    "option4": "TERMINATED",
    "answer": 2,
    "otherInfo": "A thread object created but not yet started via start() is in the NEW state."
  },
  {
    "id": 146,
    "question": "What is the result of applying the logical NOT operator twice?",
    "code": "public class DoubleNot {\n    public static void main(String[] args) {\n        boolean val = true;\n        System.out.println(!!val);\n    }\n}",
    "image": "",
    "option1": "false",
    "option2": "true",
    "option3": "Compilation Error",
    "option4": "1",
    "answer": 2,
    "otherInfo": "!val turns true to false; the second ! turns false back to true."
  },
  {
    "id": 147,
    "question": "What will happen when you try to create an object of an abstract class?",
    "code": "abstract class Test {}\npublic class Main {\n    public static void main(String[] args) {\n        // Test t = new Test();\n    }\n}",
    "image": "",
    "option1": "Compiles and instantiates Test object",
    "option2": "Uncommenting line causes Compilation Error: Test is abstract; cannot be instantiated",
    "option3": "Throws InstantiationException at runtime",
    "option4": "NullPointerException",
    "answer": 2,
    "otherInfo": "Abstract classes cannot be instantiated directly using 'new'."
  },
  {
    "id": 148,
    "question": "What is the output of searching an un-sorted array using Arrays.binarySearch()?",
    "code": "import java.util.Arrays;\npublic class BinSearch {\n    public static void main(String[] args) {\n        int[] arr = {3, 1, 2};\n        System.out.println(Arrays.binarySearch(arr, 2) >= 0);\n    }\n}",
    "image": "",
    "option1": "Guaranteed true",
    "option2": "Undefined / Undefined behavior (binarySearch requires sorted array)",
    "option3": "Compilation Error",
    "option4": "Always returns false",
    "answer": 2,
    "otherInfo": "Arrays.binarySearch() requires the array to be sorted beforehand; otherwise the returned result is undefined."
  },
  {
    "id": 149,
    "question": "What will be printed when catch block catches ArithmeticException and rethrows it?",
    "code": "public class CatchRethrow {\n    public static void main(String[] args) {\n        try {\n            try {\n                int a = 1 / 0;\n            } catch (ArithmeticException e) {\n                System.out.print(\"Inner \");\n                throw e;\n            }\n        } catch (Exception e) {\n            System.out.print(\"Outer\");\n        }\n    }\n}",
    "image": "",
    "option1": "Inner ",
    "option2": "Outer",
    "option3": "Inner Outer",
    "option4": "Compilation Error",
    "answer": 3,
    "otherInfo": "Inner catch executes (prints 'Inner '), then rethrows e, which gets caught by outer catch (prints 'Outer')."
  },
  {
    "id": 150,
    "question": "What is the result of using static block inside a class with no instances created?",
    "code": "class Sample {\n    static {\n        System.out.println(\"Static Block Executed\");\n    }\n}\npublic class TestStatic {\n    public static void main(String[] args) throws Exception {\n        Class.forName(\"Sample\");\n    }\n}",
    "image": "",
    "option1": "No output",
    "option2": "Static Block Executed",
    "option3": "ClassNotFoundException",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "Class.forName(\"Sample\") loads the class into JVM, which triggers execution of static initialization blocks."
  },
  {
    "id": 151,
    "question": "What will be the output of the following code involving implicit string casting in System.out.println?",
    "code": "public class PrintCast {\n    public static void main(String[] args) {\n        System.out.println('A' + 'B');\n    }\n}",
    "image": "",
    "option1": "AB",
    "option2": "131",
    "option3": "A B",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "Without a String operand, the addition operator '+' performs primitive integer addition on char values (65 + 66 = 131)."
  },
  {
    "id": 152,
    "question": "What will happen when executing a synchronized block on a null reference?",
    "code": "public class SyncNull {\n    public static void main(String[] args) {\n        Object lock = null;\n        synchronized (lock) {\n            System.out.println(\"Inside\");\n        }\n    }\n}",
    "image": "",
    "option1": "Prints: Inside",
    "option2": "Compilation Error",
    "option3": "NullPointerException at runtime",
    "option4": "IllegalMonitorStateException at runtime",
    "answer": 3,
    "otherInfo": "Attempting to acquire a monitor lock on a null reference using synchronized throws NullPointerException at runtime."
  },
  {
    "id": 153,
    "question": "What is the output of comparing primitive double and float values using double equal (==)?",
    "code": "public class FloatCompare {\n    public static void main(String[] args) {\n        float f = 0.1f;\n        double d = 0.1;\n        System.out.println(f == d);\n    }\n}",
    "image": "",
    "option1": "true",
    "option2": "false",
    "option3": "Compilation Error",
    "option4": "ArithmeticException",
    "answer": 2,
    "otherInfo": "0.1 cannot be represented precisely in binary floating-point. The double representation has more precision bits than float, making them unequal values when f is promoted to double."
  },
  {
    "id": 154,
    "question": "What will be printed when overriding a static method in Java?",
    "code": "class Parent {\n    static void display() { System.out.print(\"Parent \"); }\n}\nclass Child extends Parent {\n    static void display() { System.out.print(\"Child \"); }\n}\npublic class StaticOverride {\n    public static void main(String[] args) {\n        Parent p = new Child();\n        p.display();\n    }\n}",
    "image": "",
    "option1": "Child ",
    "option2": "Parent ",
    "option3": "Compilation Error",
    "option4": "Runtime Exception",
    "answer": 2,
    "otherInfo": "Static methods cannot be overridden; they are hidden (method hiding). Static resolution happens at compile-time based on the reference type (Parent)."
  },
  {
    "id": 155,
    "question": "What happens when using a primitive short inside a compound assignment operator?",
    "code": "public class CompoundAssignment {\n    public static void main(String[] args) {\n        short s = 5;\n        s += 10;\n        // s = s + 10;\n        System.out.println(s);\n    }\n}",
    "image": "",
    "option1": "Compilation error on 's += 10'",
    "option2": "Prints: 15",
    "option3": "Runtime Exception",
    "option4": "Prints: 5",
    "answer": 2,
    "otherInfo": "Compound assignment operators (+=, -=) implicitly insert an explicit cast: `s = (short)(s + 10)`, making `s += 10` compile and run cleanly, unlike `s = s + 10` which causes an implicit conversion error."
  },
  {
    "id": 156,
    "question": "What will be the output when passing primitive wrapper objects into Collections.singletonList() and modifying it?",
    "code": "import java.util.*;\npublic class SingletonListTest {\n    public static void main(String[] args) {\n        List<String> list = Collections.singletonList(\"MNC\");\n        list.add(\"Java\");\n    }\n}",
    "image": "",
    "option1": "Compiles and updates list to [MNC, Java]",
    "option2": "UnsupportedOperationException at runtime",
    "option3": "ConcurrentModificationException at runtime",
    "option4": "Compilation Error",
    "answer": 2,
    "otherInfo": "Collections.singletonList() returns an immutable list containing only one element. Invoking structural operations like add() or remove() throws UnsupportedOperationException."
  },
  {
    "id": 157,
    "question": "What is the output of using default methods with interface inheritance when a class implements both sub-interface and super-interface?",
    "code": "interface Base {\n    default void log() { System.out.print(\"Base \"); }\n}\ninterface Sub extends Base {\n    default void log() { System.out.print(\"Sub \"); }\n}\npublic class DefaultImpl implements Sub, Base {\n    public static void main(String[] args) {\n        new DefaultImpl().log();\n    }\n}",
    "image": "",
    "option1": "Base ",
    "option2": "Sub ",
    "option3": "Compilation Error due to duplicate default methods",
    "option4": "Runtime Exception",
    "answer": 2,
    "otherInfo": "Sub interface extends Base and overrides log(). In interface inheritance hierarchy, the most specific default method implementation (Sub) is chosen."
  },
  {
    "id": 158,
    "question": "What will be printed when calling String.intern() on a newly allocated heap string?",
    "code": "public class InternTest {\n    public static void main(String[] args) {\n        String s1 = new String(\"Interview\");\n        String s2 = s1.intern();\n        String s3 = \"Interview\";\n        System.out.println((s1 == s2) + \" \" + (s2 == s3));\n    }\n}",
    "image": "",
    "option1": "true true",
    "option2": "false true",
    "option3": "false false",
    "option4": "true false",
    "answer": 2,
    "otherInfo": "intern() returns the canonical instance from the String Constant Pool. s1 refers to heap object (s1 == s2 is false), while s2 and s3 both refer directly to the pool reference (s2 == s3 is true)."
  },
  {
    "id": 159,
    "question": "What is the result of using labels with break statements in nested loops?",
    "code": "public class LabeledBreak {\n    public static void main(String[] args) {\n        outer: for (int i = 0; i < 3; i++) {\n            for (int j = 0; j < 3; j++) {\n                if (i == 1) break outer;\n                System.out.print(i + \"\" + j + \" \");\n            }\n        }\n    }\n}",
    "image": "",
    "option1": "00 01 02 ",
    "option2": "00 01 02 10 11 12 ",
    "option3": "00 01 02 20 21 22 ",
    "option4": "Compilation Error",
    "answer": 1,
    "otherInfo": "When i reaches 1, `break outer;` terminates the outer loop immediately, stopping all further iteration."
  },
  {
    "id": 160,
    "question": "What will happen when throwing an exception inside a static initialization block?",
    "code": "public class ExceptionInStatic {\n    static {\n        int res = 10 / 0;\n    }\n    public static void main(String[] args) {\n        System.out.println(\"Main executed\");\n    }\n}",
    "image": "",
    "option1": "Prints: Main executed",
    "option2": "java.lang.ArithmeticException at runtime",
    "option3": "java.lang.ExceptionInInitializerError at runtime",
    "option4": "Compilation Error",
    "answer": 3,
    "otherInfo": "Uncaught exceptions occurring within static initializers are wrapped by the JVM and thrown as `java.lang.ExceptionInInitializerError`."
  }
]