Java 中 /* */ 和 /** */ 注释有什么区别?


多行注释 (/* */) 用于对源码中的多行进行注释。

示例

直播演示

public class CommentsExample {
   /*
      Following is the main method here,
      We create a variable named num.
      And, print its value    
   * */
   public static void main(String args[]) {
      //Declaring a variable named num
      int num = 1;
      //Printing the value of the variable num
      System.out.println("value if the variable num: "+num);
   }
}

输出

value if the variable num: 1

文档注释 (/** */) 用于使用 Javadoc 工具生成源码文档。

Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

示例

直播演示

/**
   * @author Tutorialspoint
*/ 
public class CommentsExample {
   public static void main(String args[]) {
      int num = 1;      
      System.out.println("value if the variable num: "+num);
   }
}

输出

value if the variable num: 1

你可以使用 Javadoc 命令生成上述类的 Java 文档:-

C:\Sample>javadoc CommentsExample.java

更新于: 2019-07-30

624 次浏览

开启你的 职业生涯

完成课程即可获得认证

立即开始
广告