Resume类图及输出效果如下。
类名:Resume
name : String (private)
sex : String (private)
age : int (private)
Resume() //没有参数的空构造方法
Resume(String name, String sex, int age) //得到各个属性值的方法getXxx()
introduce() : void //自我介绍(利用属性)
程序运行结果如下:
姓名:李四性别:男年龄:20
class Resume{
private String name;
private String sex;
private int age;
public Resume(){
}
public Resume(String name,String sex,int age){
this.name=name;
this.sex=sex;
this.age=age;
}
public String getName() {
return name;
}
public String getSex(){
return sex;
}
public int getAge(){
return age;
}
public void introduce(){
System.out.println("姓 名 :"+this.getName()+" 性 别 :"+this.getSex()+" 年 龄 :"+this.getAge());
}
}
public class 一 {
public static void main(String[] args) {
Resume re = new Resume("李四","男",20);
re.introduce();
}
}
运行结果如下