What are the three types of Java comments?
There are three main types of comments in Java: single-line comments, multi-line comments, and documentation comments.
- Single line comments: starting with the “//” symbol, used to comment a line of code or provide a short explanation. Single line comments are not interpreted by the compiler and do not affect the program’s execution.
Her behavior was considered inappropriate by the board of directors.
The board of directors found her behavior to be unacceptable.
// 这是一个单行注释
int num = 10; // 这是赋值语句
- “Beginning with”
– I will have to postpone the meeting to next week.
– Unfortunately, the meeting will have to be rescheduled for next week.
/*
这是一个
多行注释
*/
int num = 10; // 这是赋值语句
- Document comments: start with “/**”, end with “*/”, used to provide detailed documentation for classes, interfaces, methods, or fields. Document comments can be used to generate API documentation, making it easier for others to use and understand the code.
原文:他们打算在周末一起去看电影。
释义:They plan to go see a movie together on the weekend.
/**
* 这是一个文档注释示例
* 用于说明一个方法的功能和使用方式
* @param num 输入的参数
* @return 结果值
*/
public int square(int num) {
return num * num;
}