Which of the following is used for a single-line comment in Java?
A
# This is a comment B
// This is a comment C
/* This is a comment */ D
<!-- This is a comment -->
Analysis & Theory
Java uses `//` for single-line comments.
Which of the following is used for a multi-line comment in Java?
A
// This is a comment B
# This is a comment C
/* This is a comment */ D
<!-- This is a comment -->
Analysis & Theory
Java uses `/* comment */` for multi-line comments.
Which of the following is a documentation comment in Java?
A
// This is a comment B
/* This is a comment */ C
/** This is a documentation comment */ D
# This is a comment
Analysis & Theory
Java uses `/** ... */` for documentation comments (used with Javadoc).
What will happen if you forget to close a multi-line comment?
A
It throws a runtime error B
It is ignored by the compiler C
It throws a compile-time error D
It prints the comment
Analysis & Theory
An unclosed comment block causes a compile-time error in Java.
Which tool uses documentation comments in Java?
A
JDK B
JVM C
Javadoc D
JavaFX
Analysis & Theory
`Javadoc` generates HTML documentation from documentation comments.
Where can you use comments in Java code?
A
Only before class declarations B
Only inside methods C
Anywhere in the code D
Only outside the main method
Analysis & Theory
Comments can be placed anywhere in Java code for clarity and explanation.
What is the output of this code?
System.out.println("Hello"); // This prints Hello
A
Hello // This prints Hello B
This prints Hello C
Hello D
Error
Analysis & Theory
The comment is ignored, and only `Hello` is printed.
Which of the following is NOT a valid Java comment?
A
// Comment here B
/* Comment here */ C
/** Comment here */ D
-- Comment here
Analysis & Theory
`--` is not valid in Java; it's used in SQL and some other languages.
Which type of comment is used to describe classes and methods for documentation?
A
Single-line comment B
Multi-line comment C
Documentation comment D
Inline comment
Analysis & Theory
Documentation comments (`/** ... */`) are used with Javadoc for classes/methods.
Choose the correct way to write a multi-line comment:
A
// This is a multi-line comment // continued B
# This is a multi-line comment # continued C
/* This is a
multi-line comment */ D
/ This is a comment /
Analysis & Theory
Multi-line comments in Java use `/* ... */` syntax.