关于Javadoc的疑惑~

一直以来都不太懂javadoc怎么用,用eclipse生成出的doc只有主方法。不明白问题在哪

晚上突然灵感乍现,莫非javadoc只能生成和文件名相同类的方法么?

于是写了测试类:


/**
 * 测试javadoc生成器
 * @author Eric
 * @version 1.0
 */
public class TestJavadoc {
	/**
	 * 成员变量姓名
	 */
	private String name;
	/**
	 * 成员变量年龄
	 */
	private int age;
	/**
	 * 成员变量java成绩
	 */
	private float javaScore;
	/**
	 * 无参构造方法
	 */
	TestJavadoc() {
		this.name = null;
		this.age = 0;
		this.javaScore = 0.0f;
		System.out.println("无参构造方法已建立");
	}
	/**
	 * 有参构造方法
	 * @param n
	 * @param a
	 * @param s
	 */
	TestJavadoc(String n,int a,float s) {
		this.name = n;
		this.age = a;
		this.javaScore = s;
		System.out.println("有参构造方法已建立");
	}
	/**
	 * name setter方法
	 * @param n
	 */
	public void setName(String n) {
		this.name = n;
	}
	/**
	 * name getter方法
	 * @return String
	 */
	public String getName() {
		return this.name;
	}
	public void say() {
		System.out.println("姓名:"+ this.name + "\n年龄:" + this.age + "\nJava成绩:" + 
				this.javaScore);
	}
	
	public static void main(String args[]) {
		TestJavadoc test = new TestJavadoc("eric",27,85f);
		test.say();
	}
}
doc文档被成功创建,看来和我想的一样,只有和名字同名的类中的成员变量和成员方法才能被识别。


那么下一个疑问就来了,看来我以前的程序都写在一个类中是不对的,应该创建自己的类文件,同时在一个包中。于是再次测试:


package eric.practice;
/**
 * Employee抽象类
 * @author Eric
 */

public abstract class Employee {
	/**
	 * 姓名、年龄、性别
	 */	
	private String name;
	private int age;
	private char sex;
	/**
	 * 构造方法
	 */	
	Employee(String name,int age,char sex) {
		this.name = name;
		this.age = age;
		this.sex = sex;
	}
	/**
	 *设置姓名,setter方法
	 *@param name 姓名
	 */	
	public void setName(String name) {
		this.name = name;
	}
	/**
	 *设置年龄,setter方法
	 *@param age 年龄
	 */	
	public void setAge(int age) {
		this.age = age;
	}	
	/**
	 *设置性别,setter方法
	 */	
	public void setSex(char sex) {
		this.sex = sex;
	}
	/**
	 *得到姓名,getter方法
	 */	
	public String getName() {
		return name;
	}	
	/**
	 * 得到年龄,getter方法
	 */
	public int getAge() {
		return age;
	}
	/**
	 * 得到性别,getter方法
	 */
	public char getSex() {
		return sex;
	}
	/**
	 * 抽象方法info
	 */
	abstract void info() ;
	
}


package eric.practice;
/**
 * Maneger类继承Employee抽象类
 * @author Eric
 *
 */
public class Maneger extends Employee {
	private String post;
	private float salary;
	
	Maneger(String name,int age,char sex,String post,float salary) {
		super(name, age, sex);
		this.post = post;
		this.salary = salary;
	}
	
	public void setPost(String post) {
		this.post = post;
	}
	public void setSalary(float salary) {
		this.salary = salary;
	}
	public String getPost() {
		return post;
	}
	public float getSalary() {
		return salary;
	}
	@Override	
	public void info() {
		System.out.println("=====Maneger Info=====\n" + "员工姓名:" + super.getName() + "\n员工年龄:" + super.getAge() + "\n员工性别:" + super.getSex() + "\n员工级别:" + post+ "\n员工工资:" +  + salary);
	}
}
package eric.practice;
/**
 * 测试类
 * @author Eric
 */

public class TestEmployee {
	public static void main(String[] args) {
		Maneger m = new Maneger("zhao",43,'m',"maneger",50000);
		m.info();
		Staff s = new Staff("wang",28,'f',"staff",6000);
		s.info();
	}
}
需要哪个类就生成哪个类的doc。但是在生成的时候javadoc只能识别被public或者protected修饰的类的成员变量和方法。又长知识了。




转载于:https://my.oschina.net/ericdeep/blog/103145

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值