---方法区内存:在类加载的时候,class字节码代码段被加载到该内存空间中
---栈内存(局部变量):方法代码段片段执行的时候,会给该方法分配内存空间,在栈内存中压栈,执行完毕之后释放内存空间,做弹栈操作.
---堆内存(实例变量):new的对象在堆内存中存储.
方法内存分析

public class Hello {
    public static void main(String[] args) {
        int a = 100;
        int b = 200;
        int res = sum(a, b);
        System.out.println(res);
    }
    public static int sum(int i,int j)
    {
        int result = i + j;
        int num = 3;
        int res2 = devide(result, num);
        return res2;
    }
    public static int devide(int x,int y)
    {
        int z;
        z = x / y;
        return z;
    }
}

运行结果:

对象内存分析

public class Hello2 {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Student stu = new Student();
        System.out.println("姓名:" + stu.name);
        System.out.println("学号:" + stu.no);
        System.out.println("性别:" + stu.sex);
        System.out.println("年龄:" + stu.age);
        Student s = new Student();
        s.no = 10;
        s.sex = true;
        s.age = 20;
        s.name = "jack";
    s.add.city = "北京";
    s.add.street = "朝阳街道";
    s.add.zipcode = "000001";
        System.out.println("姓名:" + s.name);
        System.out.println("学号:" + s.no);
        System.out.println("性别:" + s.sex);
        System.out.println("年龄:" + s.age);
        System.out.println("城市:" + s.add.city);
        System.out.println("街道:" + s.add.street);
        System.out.println("邮政编码:" + s.add.zipcode);
    }
    public static class Student {
        String name;
        int no;
        boolean sex;
        int age;
        Address add = new Address();
    }
    public static class Address {
        String city;
        String street;
        String zipcode;
    }
}

运行结果: