代码案例一:
package android.java.oop02; class Student { public int age;
public String name; public void show() {
System.out.println("age:" + age + " name:" + name);
}
} public class OopDemo01 { public static void main(String[] args) {
Student s = new Student();
} }
代码案例一 对应的内存图:
代码案例二:
package android.java.oop02; class Student { public int age;
public String name; public void show() {
System.out.println("age:" + age + " name:" + name);
}
} public class OopDemo01 { public static void main(String[] args) {
Student s = new Student();
s.age = 19;
s.name = "mcc";
s.show();
} }
代码案例二对应的内存图:
代码案例三:
package android.java.oop02; class Teacher { public int age;
public String name; public void show() {
System.out.println("age:" + age + " name:" + name);
}
} public class OopDemo02 { public static void main(String[] args) {
Teacher t = new Teacher();
t.age = 39;
t.name = "www"; Teacher t2 = t;
t2.age = 99;
t2.name = "JACK"; t.show();
} }
执行结果:
age:99 name:JACK