请写出一个标准的学生类(Student)
/**
*学生类:用于定义学生对象
*/
class Student
{
// 姓名
private String name;
// 年龄
private int age;
// 学号
private String num;
/**无参构造函数*/
public static Student(){}
/**有参构造函数*/
public static Student(String name, int age; String num)
{
this.name = name;
this.age = age;
this.num = num;
}
/**setName方法,给name赋值*/
public void setName(String name)
{
this.name = name;
}
/**getName方法,获取name值*/
public String getName()
{
return this.name;
}
/**setAge方法*/
public void setAge(int age)
{
this.age = age;
}
/**getAge*/
public int getAge()
{
return this.age;
}
/**setNum 设置学号*/
public void setNum(String num)
{
this.num = num;
}
/**getNum 获取学号*/
public String getNum()
{
return this.num;
}
/**show 方法,输出对象的属性值*/
public void show()
{
System.out.println("姓名是" + this.name + "年龄为:" + this.age+"的学生,学号为:" + this.num);
}
} |
|