Java MCQ: Which of the following is not a valid comment in Java?
a) // This is a single-line comment
b) /* This is a multi-line comment */
c) /** This is a documentation comment */
d) / This is not a valid comment
Answer:
d) / This is not a valid comment
Explanation:
In Java, comments are used to annotate code and improve its readability. There are three types of comments: single-line comments, multi-line comments, and documentation comments. Single-line comments start with //
and extend to the end of the line. Multi-line comments are enclosed between /*
and */
, and documentation comments, used to generate API documentation, are enclosed between /**
and */
.
A comment starting with a single /
is not valid in Java and will result in a syntax error.
Understanding how to use comments effectively is important for writing clear, maintainable code and for documenting your programs.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html