堆:一般用来存放用关键字new出来的数据。
package demo;
public class Student {
private String name;
private int age;
public void study() {
System.out.println("I love study!");
}
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;
}
}
package demo;
public class StudentDemo {
public static void main(String[] args) {
Student student = new Student();
System.out.println(student.getName() + ":" + student.getAge());
student.setName("John");
student.setAge(23);
System.out.println(student.getName() + ":" + student.getAge());
student.study();
Student student2 = student;
student2.setName("Jack");
student2.setAge(25);
System.out.println(student2.getName() + ":" + student2.getAge());
System.out.println(student.getName() + ":" + student.getAge());
}
}