Android-Java-对象在内存中的简单关系图

代码案例一:

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();
} }

代码案例一 对应的内存图:

Android-Java-对象在内存中的简单关系图


代码案例二:

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();
} }

代码案例二对应的内存图:

Android-Java-对象在内存中的简单关系图


代码案例三:

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

代码案例三对应内存图:

Android-Java-对象在内存中的简单关系图

上一篇:javascript基础(1)


下一篇:Java多线程学习(五)线程间通信知识点补充