1、类与对象的基础题: 1)编程实现:设计一个学生类Student,包含的属性有姓名name和年龄age. 由学生类派

2024-12-01 04:41:51
推荐回答(1个)
回答1:

怎么不全?

public class Student {
public String name;
public int 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;
}
}
--------------------------------------------------------------------------------------------------------------
public class StudentImpl {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Student student = new Student();
student.setName("zhangsan");
student.setAge(19);
System.out.println(student.getName() + "今年" + student.getAge() +"岁。");
}

}