/*
* 学生:
* 属性: 姓名name 年龄age
* 行为:睡觉 sleep
*
* */
public class Student_Test {
public static void main(String[] args) {
new Student().setName("momo");
new Student().setAge(18);
System.out.println(new Student().getName()+"..."+new Student().getAge());
new Student().sleep();
}
}
class Student {
private String name; //封装姓名
private int age; //封装年龄
public void setName(String name){
this.name = name;
}
public String getName() {
return name;
}
public void setAge(int age){
this.age = age;
}
public int getAge(){
return age;
}
public static void sleep(){
System.out.println("上课爱睡觉!");
}
}
结果是 null 0 还有上课爱睡觉 ,前面两个答案有点不理解啊? |
|