Java Aptitude MCQ Questions with Answers for Freshers

26. What does the hashCode() method of an object represent?
  • A) A unique identifier for the object
  • B) A hash value used in collections like HashMap
  • C) A random value for the object
  • D) The object’s memory address

Answer: B) A hash value used in collections like HashMap

27. What will be the output of the following code?
String str1 = "Hello";
String str2 = "Hello";
System.out.println(str1 == str2);
  • A) true
  • B) false
  • C) Compilation error
  • D) Runtime exception

Answer: A) true

28. Which of these operators is used for bitwise AND in Java?
  • A) &&
  • B) &
  • C) ||
  • D) ^

Answer: B) &

29. In Java, the switch statement can operate on which of these data types?
  • A) int, char, byte, short, enum, String
  • B) float, char, boolean, String
  • C) double, long, char, String
  • D) boolean, int, double, String

Answer: A) int, char, byte, short, enum, String

30. Which method is automatically called when an object is garbage collected?
  • A) finalize()
  • B) clean()
  • C) destroy()
  • D) remove()

Answer: A) finalize()

31. What is the purpose of the super keyword in Java?
  • A) To refer to the current class
  • B) To refer to the parent class
  • C) To create a new object
  • D) To terminate the program

Answer: B) To refer to the parent class

32. Which of the following classes is synchronized in Java?
  • A) ArrayList
  • B) Vector
  • C) LinkedList
  • D) HashMap

Answer: B) Vector

33. Which method in the Thread class is used to check if a thread is alive?
  • A) isAlive()
  • B) checkAlive()
  • C) alive()
  • D) threadStatus()

Answer: A) isAlive()

34. What is the correct syntax for a lambda expression in Java?
  • A) (parameter) -> expression
  • B) parameter -> {expression}
  • C) (parameter) => expression
  • D) () -> expression

Answer: A) (parameter) -> expression

35. Which exception is thrown when a thread is waiting, sleeping, or doing some other operation and is interrupted?
  • A) InterruptedException
  • B) IllegalStateException
  • C) ArithmeticException
  • D) IOException

Answer: A) InterruptedException

Java MCQ Questions with Answers PDF

2 thoughts on “Java Aptitude MCQ Questions with Answers for Freshers”

Leave a Comment