您好,欢迎访问一九零五行业门户网

如何在Java代码中添加不同的注释?

java 注释是编译器和解释器不执行的语句。注释可用于提供有关变量、方法、类或任何语句的信息。它还可以用于隐藏特定时间的程序代码。
java 注释的类型java 中的注释分为三种类型。
单行注释多行注释文档注释单行注释单行注释以 // 开始,到行尾结束。
示例 1public class singlelinecomment { public static void main(string[] args) { // to print output in the console system.out.println("welcome to tutorials point"); }}
输出welcome to tutorials point


多行注释多行注释以 /* 开头,以 */ 结尾,跨多行。
示例 2public class multilinecomment { public static void main(string[] args) { /* to print the output as welcome to tutorials point in the console. */ system.out.println("welcome to tutorials point"); }}
输出welcome to tutorials point


文档注释文档样式注释以 /** 开头,以 */ 结尾,并且跨多行。文档注释必须紧接在类、接口、方法或字段定义之前。
示例 3/** this is a documentation comment. this class is written to show the use of documentation comment in java. this program displays the text "welcome to tutorials point" in the console.*/public class documentationcomment { public static void main(string args[]) { system.out.println("welcome to tutorials point"); }}
输出welcome to tutorials point


以上就是如何在java代码中添加不同的注释?的详细内容。
其它类似信息

推荐信息