Question:

Which is the correct way to write multiline comments in a Java program?

Show Hint

Use /* and */ in Java to write multiline comments across several lines of code.
Updated On: Jul 14, 2025
  • Beginning a comment line with two consecutive forward slashes (//).
  • Writing a comment between the symbols /* and */.
  • Beginning a comment line with # symbol.
  • Writing the comment between the symbols /# and #/.
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

In Java, there are two types of comments: single-line and multi-line comments.
- Single-line comments begin with two forward slashes (//) and apply only to that specific line.
- Multiline comments start with /* and end with */. These can span multiple lines.
This format allows developers to comment out blocks of code or provide lengthy documentation within the code.
Option (B) is the correct method for writing multiline comments in Java.
Options (C) and (D) use syntax not valid in Java — the hash symbol (#) is not recognized for commenting in Java.
Option (A) is only valid for single-line comments, not multiline ones.
Was this answer helpful?
0
0