Core Java Deep Dive MCQs

  1. What will be printed?
    1 System.out.println("Eduinq".length());
    a) 5
    b) 6
    c) 7
    d) Compilation error
    View Answer

    Correct answer: B — 6

  2. Which of the following is true about Strings in Java?
    a) Strings are immutable
    b) Strings are mutable
    c) Strings are stored only in heap
    d) Strings cannot be concatenated
    View Answer

    Correct answer: A — Strings are immutable

  3. What will be printed?
    1 String s = "Eduinq";
    2 System.out.println(s.toUpperCase());
    a) eduinq
    b) EDUINQ
    c) Eduinq
    d) Compilation error
    View Answer

    Correct answer: B — EDUINQ

  4. Which of the following is true about arrays in Java?
    a) Arrays are objects
    b) Arrays have fixed size
    c) Arrays can store primitive and objects
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  5. What will be printed?
    1 int[] arr = {1,2,3};
    2 System.out.println(arr[1]);
    a) 1
    b) 2
    c) 3
    d) Compilation error
    View Answer

    Correct answer: B — 2

  6. Which of the following is true about exceptions in Java?
    a) Checked exceptions must be handled or declared
    b) Unchecked exceptions are subclasses of RuntimeException
    c) Errors are not meant to be caught
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  7. What will be printed?
    1 try {
    2 int x = 10/0;
    3 } catch(Exception e) {
    4 System.out.println("Eduinq Exception");
    5 }
    a) Eduinq Exception
    b) Compilation error
    c) Runtime exception
    d) None
    View Answer

    Correct answer: A — Eduinq Exception

  8. Which of the following is true about wrapper classes?
    a) They convert primitives to objects
    b) They provide utility methods
    c) They support autoboxing/unboxing
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  9. What will be printed?
    1 Integer i = Integer.valueOf("100");
    2 System.out.println(i + 50);
    a) 100
    b) 150
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: B — 150

  10. Which of the following is true about finally block?
    a) Executes whether exception occurs or not
    b) Executes even if return statement is present
    c) Does not execute if JVM exits
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  11. What will be printed?
    1 String s = "Eduinq";
    2 System.out.println(s.charAt(2));
    a) d
    b) u
    c) i
    d) Compilation error
    View Answer

    Correct answer: B — u

  12. Which of the following is true about StringBuilder?
    a) Mutable
    b) Faster than StringBuffer in single threaded context
    c) Not synchronized
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  13. What will be printed?
    1 StringBuilder sb = new StringBuilder("Eduinq");
    2 sb.append(" Portal");
    3 System.out.println(sb);
    a) Eduinq
    b) Eduinq Portal
    c) Portal
    d) Compilation error
    View Answer

    Correct answer: B — Eduinq Portal

  14. Which of the following is true about StringBuffer?
    a) Mutable
    b) Thread safe
    c) Slower than StringBuilder in single threaded context
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  15. What will be printed?
    1 int[] arr = new int[3];
    2 System.out.println(arr[0]);
    a) 0
    b) null
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — 0

  16. Which of the following is true about NullPointerException?
    a) Occurs when accessing methods on null reference
    b) Is unchecked
    c) Subclass of RuntimeException
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  17. What will be printed?
    1 try {
    2 String s = null;
    3 System.out.println(s.length());
    4 } catch(NullPointerException e) {
    5 System.out.println("Eduinq NullPointer");
    6 }
    a) Eduinq NullPointer
    b) Compilation error
    c) Runtime exception
    d) None
    View Answer

    Correct answer: A — Eduinq NullPointer

  18. Which of the following is true about autoboxing?
    a) Converts primitive to wrapper automatically
    b) Introduced in Java 5
    c) Works with collections
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  19. What will be printed?
    1 Integer i = 10;
    2 int j = i;
    3 System.out.println(j);
    a) 10
    b) Compilation error
    c) Runtime exception
    d) None
    View Answer

    Correct answer: A — 10

  20. Which of the following is true about ArrayIndexOutOfBoundsException?
    a) Occurs when accessing invalid index
    b) Is unchecked
    c) Subclass of RuntimeException
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  21. What will be printed?
    1 String s = "Eduinq Portal";
    2 System.out.println(s.indexOf("Portal"));
    a) 7
    b) 6
    c) 8
    d) Compilation error
    View Answer

    Correct answer: A — 7

  22. Which of the following is true about String.equals() vs ==?
    a) equals() compares values
    b) == compares references
    c) Both A and B
    d) None
    View Answer

    Correct answer: C — Both A and B

  23. What will be printed?
    1 String s1 = new String("Eduinq");
    2 String s2 = new String("Eduinq");
    3 System.out.println(s1 == s2);
    a) true
    b) false
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: B — false

  24. Which of the following is true about arrays?
    a) Length is fixed
    b) Index starts at 0
    c) Accessing invalid index throws exception
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  25. What will be printed?
    1 int[] arr = {10,20,30};
    2 System.out.println(arr.length);
    a) 2
    b) 3
    c) 4
    d) Compilation error
    View Answer

    Correct answer: B — 3

  26. Which of the following is true about try-catch-finally?
    a) Finally always executes unless JVM exits
    b) Catch handles exceptions
    c) Try defines risky code
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  27. What will be printed?
    1 try {
    2 int[] arr = new int[2];
    3 System.out.println(arr[5]);
    4 } catch(ArrayIndexOutOfBoundsException e) {
    5 System.out.println("Eduinq Array Exception");
    6 }
    a) Eduinq Array Exception
    b) Compilation error
    c) Runtime exception
    d) None
    View Answer

    Correct answer: A — Eduinq Array Exception

  28. Which of the following is true about custom exceptions?
    a) Must extend Exception or RuntimeException
    b) Can have constructors
    c) Can override getMessage()
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  29. What will be printed?
    1 try {
    2 throw new Exception("Eduinq Custom Exception");
    3 } catch(Exception e) {
    4 System.out.println(e.getMessage());
    5 }
    a) Eduinq Custom Exception
    b) Compilation error
    c) Runtime exception
    d) None
    View Answer

    Correct answer: A — Eduinq Custom Exception

  30. Which of the following is true about wrapper classes?
    a) Integer wraps int
    b) Double wraps double
    c) Boolean wraps boolean
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  31. What will be printed?
    1 Integer i = Integer.parseInt("200");
    2 System.out.println(i);
    a) 200
    b) Compilation error
    c) Runtime exception
    d) None
    View Answer

    Correct answer: A — 200

  32. Which of the following is true about NumberFormatException?
    a) Occurs when parsing invalid number string
    b) Is unchecked
    c) Subclass of RuntimeException
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  33. What will be printed?
    1 try {
    2 Integer.parseInt("Eduinq");
    3 } catch(NumberFormatException e) {
    4 System.out.println("Eduinq Number Exception");
    5 }
    a) Eduinq Number Exception
    b) Compilation error
    c) Runtime exception
    d) None
    View Answer

    Correct answer: A — Eduinq Number Exception

  34. Which of the following is true about String.valueOf()?
    a) Converts primitive to String
    b) Converts object to String
    c) Returns "null" if object is null
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  35. What will be printed?
    1 System.out.println(String.valueOf(123) + "Eduinq");
    a) 123Eduinq
    b) Eduinq123
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — 123Eduinq

  36. Which of the following is true about Arrays.toString()?
    a) Converts array to readable string
    b) Returns memory reference
    c) Throws exception
    d) None
    View Answer

    Correct answer: A — Converts array to readable string

  37. What will be printed?
    1 int[] arr = {1,2,3};
    2 System.out.println(java.util.Arrays.toString(arr));
    a) [1, 2, 3]
    b) 123
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — [1, 2, 3]

  38. Which of the following is true about String.split()?
    a) Splits string into array
    b) Uses regex
    c) Returns array of substrings
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  39. What will be printed?
    1 String s = "Eduinq,Portal";
    2 String[] parts = s.split(",");
    3 System.out.println(parts[1]);
    a) Eduinq
    b) Portal
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: B — Portal

  40. Which of the following is true about String.trim()?
    a) Removes leading spaces
    b) Removes trailing spaces
    c) Does not remove middle spaces
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  41. What will be printed?
    1 String s = " Eduinq ";
    2 System.out.println(s.trim());
    a) Eduinq
    b) " Eduinq "
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq

  42. Which of the following is true about String.compareTo()?
    a) Returns 0 if equal
    b) Returns positive if greater
    c) Returns negative if smaller
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  43. What will be printed?
    1 System.out.println("Eduinq".compareTo("Portal"));
    a) Negative number
    b) Positive number
    c) 0
    d) Compilation error
    View Answer

    Correct answer: A — Negative number

  44. Which of the following is true about String.contains()?
    a) Checks if substring exists
    b) Returns boolean
    c) Case sensitive
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  45. What will be printed?
    1 System.out.println("Eduinq Portal".contains("Portal"));
    a) true
    b) false
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — true

  46. Which of the following is true about String.isEmpty()?
    a) Returns true if length is 0
    b) Returns false if length > 0
    c) Throws exception if null
    d) Both A and B
    View Answer

    Correct answer: D — Both A and B

  47. What will be printed?
    1 String s = "";
    2 System.out.println(s.isEmpty());
    a) true
    b) false
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — true

  48. Which of the following is true about StringBuilder.reverse()?
    a) Reverses characters in string builder
    b) Returns same object
    c) Useful for palindrome check
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  49. What will be printed?
    1 StringBuilder sb = new StringBuilder("Eduinq");
    2 System.out.println(sb.reverse());
    a) qniudE
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — qniudE

  50. Which of the following is true about exception hierarchy in Java?
    a) Throwable is superclass of all errors and exceptions
    b) Exception is subclass of Throwable
    c) RuntimeException is subclass of Exception
    d) All of the above
    View Answer

    Correct answer: D — All of the above

Quick Links to Explore