class Student
{
//姓名
private String name;
//年龄
private int age;
//构造方法
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;
}
//输出所有的成员变量的值
public void show(){
System.out.println(name+"----"+age);
}
//测试类
class StudentTest
{
public static void main(String[]args){
//方式一给成员变量赋值
//无参构造+setXxx()
Student s1 = new Student();
s1.setName("林青霞");
s1.setAge(27);
//输出值
System.out.println(s1.getName()+"----"+s1.getAge());
s1.show();
System.out.println("-----------------------");
//方式二给成员变量赋值
Student s2 = new Student("刘一",30);
System.out.println(s2.getName()+"----"+s2.getAge());
s2.show();
}
}
}