Java编程入门与应用 例8-19——高手带你做:查看个人信息
员工信息类:
/**
* 员工信息
*/
public class person {
//私有信息:员工姓名
private String name;
//私有信息:员工年龄
private int age;
//私有信息:员工性别
private String sex;
//私有信息:员工出生日期
private String birthday;
//私有信息:员工星座
private String constellation;
//自定义构造方法
person(String name, int age, String sex, String birthday, String constellation){
this.name = name;
this.age = age;
this.sex = sex;
this.birthday = birthday;
this.constellation = constellation;
}
//输出信息的方法
public void intro(){
System.out.println(
"姓名:" + this.name + "\n年龄:" + this.age + "\n性别:" + this.sex + "\n出生日期:" + this.birthday
+ "\n星座:" + this.constellation
);
}
}
程序入口
/**
* Java编程入门与应用 例8-19——高手带你做:查看个人信息
*/
public class personInformation {
public static void main(String[] args) {
person person = new person("王洁", 21, "女", "2016-02-21", "狮子座");
person.intro();
}
}
结果:
姓名:王洁
年龄:21
性别:女
出生日期:2016-02-21
星座:狮子座
进程已结束,退出代码为 0
感谢观看
再次感谢~