给你个我写的例子吧
class Student
{ private String name;
private int age;
public Student(){};
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;
}
}
class Test
{
public static void main(String[] args)
{
Student s= new Student();
s.setName("king");
s.setAge(10);
System.out.println("名字:"+s.getName()+"年龄:"+s.getAge());
}
}