java程序设计学习第七天
(学习调用方法及其写入值)
package glc;
public class glc {
private String name;
private double age;
private boolean male;
public void setMale(boolean boy) {
male=boy;
}
public boolean isMale() {
return male;
}
public void setAge(double num) {
if(num < 200 && num >= 0) {
age=num;
}
else {
System.out.println(“数据不合理”);
}
}
public double getAge() {
return age;
}
public void setName(String name) {
this.name=name;
}
public String getName() {
return name;
}
public void show() {
System.out.println(“我叫:” + name + " 年龄:" + age);
}
}
package glc;
public class glc5 {
public static void main(String[] args) {
glc glc5=new glc();//调用方法
glc5.setAge(19);//写入值
glc5.setName(“小志”);
glc5.setMale(false);
glc5.show();
if(glc5.isMale()==true) {
System.out.println(“男”);//读出值
}
else {
System.out.println(“女”);
}
}
}