《疯狂JAVA讲义》第五章的作业,一个简单的student 类:
public class Student
{
public String name;
public int age;
public String gender;
public String phone;
public String address;
public String email;
void setter_name(String name1)
{
this.name = name1;
}
String getter_name()
{
return this.name;
}
public static void main(String[] args)
{
Student ss = new Student();
String name1 = "guilan";
//Could not directly use this.setter_name(name1), because static function could not call non-static function.
//本来是用this.setter_name(name1)这样的方式来调用setter_name, 但是编译器会报错,在static 函数中不能调用non-static函数
ss.setter_name(name1);
System.out.println("Name is: " + ss.getter_name());
}
}
还可以用另一种方式来实现,那就是把main 放在另一个类中(比如StudentTest)。