[Java] 纯文本查看 复制代码
public class Student {
private String name;
public Student() {
}
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
private int age;
public void eat() {
System.out.println("吃饭饭");
}
public void sleep() {
System.out.println("睡觉觉");
}
public void study() {
System.out.println("学习");
}
}
[Java] 纯文本查看 复制代码
public static void main(String[] args) {
//无参构造使用
Student s = new Student();
s.setName("舒畅");
s.setAge(18);
System.out.println(s.getName()+"‐‐‐"+s.getAge());
//带参构造使用
Student s2 = new Student("赵丽颖",18);
System.out.println(s.getName()+"‐‐‐"+s.getAge());
}