示例程序如下,这是我测试通过的,不知道在您那里能不能通过?期盼众位的反馈!^_^ 这是原创文章,转载请注明原出处! 该文章首次发表位置: http://blog.csdn.net/niko7/
以下为代码: package gfh.test;
/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author 顾法华,杭州 * @version 1.0 */ public class 人 { static public void main(String[] 输入参数) { gfh.test.人 某一个人 = new 人(); 某一个人.set姓("天才"); 某一个人.set名("阿三"); 某一个人.set年龄(18); System.out.print( 某一个人.toString() ); } private String 姓 = "[姓]"; private String 名 = "[未取名]"; private int 年龄 = 0; public 人() { super(); }
public void set姓(String 姓) { this.姓 = (null==姓)?"":姓; }
public void set名(String 名) { this.名 = (null==名)?"":名; }
public void set年龄(int 年龄) { this.年龄 = 年龄%150; }
public String get姓() { return 姓; }
public String get名() { return 名; }
public int get年龄() { return 年龄; } public String toString() { return this.get姓()+this.get名()+","+this.get年龄()+"岁"; } }
运行后输出如下: 天才阿三,18岁

|