AllInfoHub Logo

AllInfoHub – MCQ Practice

Introduction to Java – Multiple Choice Questions (MCQs)

  1. 13. Which of the following is a single-line comment in Java?

    • A. // comment
    • B. /* comment */
    • C.
    • D. ## comment
  2. 14. Which of the following is a multi-line comment in Java?

    • A. // comment
    • B. /* comment */
    • C.
    • D. ## comment
  3. 15. What is the purpose of `System.out.println()`?

    • A. To read input from the console
    • B. To print output to the console with a newline
    • C. To print output to the console without a newline
    • D. To format output
  4. 16. What is the output of `System.out.println(2 + 3 * 4);`?

    • A. 14
    • B. 20
    • C. 12
    • D. 10
  5. 17. Which of the following is a primitive data type in Java?

    • A. String
    • B. Integer
    • C. Boolean
    • D. int
  6. 18. Which of the following is a reference data type in Java?

    • A. int
    • B. float
    • C. boolean
    • D. String
  7. 19. What is the default value of an integer variable in Java?

    • A. 0
    • B. null
    • C. undefined
    • D. depends on the JVM
  8. 20. What is the default value of a boolean variable in Java?

    • A. TRUE
    • B. FALSE
    • C. null
    • D. 0
  9. 21. What is the default value of a reference variable in Java?

    • A. 0
    • B. null
    • C. undefined
    • D. an empty string
  10. 22. Which keyword is used to declare a constant variable in Java?

    • A. const
    • B. final
    • C. immutable
    • D. static
  11. 23. What is the output of `System.out.println(5 / 2);`?

    • A. 2.5
    • B. 2
    • C. 2
    • D. 3
  12. 24. What is the output of `System.out.println(5 % 2);`?

    • A. 1
    • B. 2
    • C. 2.5
    • D. 0