定义一个类:
public class Student {
String name;
int age;
public void student()
{
System.out.println("学习...");
}
public void eat(){
System.out.println("吃饭...");
}
}
定义一个测试类:
public class StudentTest {
public static void main(String[] args) {
Student stu1=new Student();
stu1.name="张三";
stu1.age=18;
System.out.println(stu1.age);
System.out.println(stu1.name);
stu1.student();
stu1.eat();
System.out.println("-------------");
Student stu2=new Student();
stu2.name="李四";
stu2.age=20;
System.out.println(stu2.name);
System.out.println(stu2.age);
stu2.student();
stu2.eat();
}
}
标签:stu2,stu1,对象,System,Student,println,out
From: https://blog.51cto.com/u_15988249/6222005