第一题
文档注释可以在 类、接口、方法、成员变量、构造器和内部类之前;
并且使用javadoc命令工具进行生成;
有一些标记比如:
1. 在类或者接口文档中:@deprecated,@see,@author,@version
2. 方法或者构造器文档注释中:@deprecated,@param,@return,@throws,@exception
3. 成员变量的文档注释当中:@see,@deprecated
并且由于javadoc工具不会提取@author,@version所以如果需要提取这两个标记那么需要在使用javadoc工具时候指定 -author ,-version。
/**
* Describtion:
* @author: tris_tan
* @version: 1.0
*/
class Teacher
{
static int teacherNum = 0;
private String name;
private int age;
private String project;
public Teacher(String name, int age, String project)
{
this.name = name;
this.age = age;
this.project = project;
}
public void show()
{
System.out.println("This student name is "+name +" , and "+ age +" years old . Her/Him project is "+ project +" ." );
}
}
class Student
{
static int stuNum = 0;
private String name;
private int age;
public Student(String name, int age)
{
this.name = name;
this.age = age;
}
public void show()
{
System.out.println("This student name is "+name +" , and "+ age+" years old ." );
}
}
class ClassRoom
{
static int roomNum = 0;
private String roomName;
private int roomSeats;
public ClassRoom(String name, int seats)
{
this.roomName = name;
this.roomSeats = seats;
}
public void show()
{
System.out.println("This is "+roomName+" room ." +" And this room can contain "+ roomSeats+" people." );
}
}
public class test{
public static void main (String[] args)
{
Teacher tea = new Teacher("lili", 25 , "math" );
Student stu = new Student("max",12);
ClassRoom room = new ClassRoom("B521",102);
tea.show();
stu.show();
room.show();
}
}
生成的api文档大致如下: