AllInfoHub Logo

AllInfoHub – MCQ Practice

Introduction to Java – Multiple Choice Questions (MCQs)

  1. 25. Which operator is used for equality comparison in Java?

    • A. =
    • B. ==
    • C. ===
    • D. equals()
  2. 26. Which operator is used for assignment in Java?

    • A. =
    • B. ==
    • C. ===
    • D. equals()
  3. 27. What is the output of `System.out.println(Hello" + "World");`?"

    • A. HelloWorld
    • B. Hello World
    • C. Hello World
    • D. Error
  4. 28. What is the output of `System.out.println(5 == 5.0);`?

    • A. TRUE
    • B. FALSE
    • C. error
    • D. depends on JVM
  5. 29. What is the output of `System.out.println(5 === 5.0);`?

    • A. TRUE
    • B. FALSE
    • C. error
    • D. depends on JVM
  6. 30. Which of the following is NOT a valid identifier in Java?

    • A. myVariable
    • B. my_variable
    • C. 1stVariable
    • D. $variable
  7. 31. What is the purpose of the `package` keyword in Java?

    • A. To define a class
    • B. To group related classes
    • C. To import other classes
    • D. To define a method
  8. 32. Which keyword is used to import classes from other packages?

    • A. import
    • B. include
    • C. using
    • D. package
  9. 33. What is the default package in Java?

    • A. java.lang
    • B. java.util
    • C. current directory (no name)
    • D. default
  10. 34. Which class is the ultimate superclass of all classes in Java?

    • A. Object
    • B. Class
    • C. Super
    • D. Base
  11. 35. What is the role of the garbage collector in Java?

    • A. To manually free up memory
    • B. To automatically manage memory allocation
    • C. To optimize code execution
    • D. To handle exceptions
  12. 36. What is the output of `System.out.println(2 << 2);`?

    • A. 4
    • B. 6
    • C. 8
    • D. 10