栈:存放局部变量。存放new出来的对象。方法区:存放类的信息(代码)、static变量、常量池(字符串常量)等。 package theChildOfGod.bjxy.oop; public class Student { //静态的数据 String name; int id; int age; String gender; int weight; //动态的行为 public void study() { System.out.println(name+ "在学习"); } public void sayHello(String sname) { System.out.println(name+ "向" + sname + "说:同志你辛苦了!"); } } package theChildOfGod.bjxy.oop; public class test1 { public static void main(String[] args) { // 通过类加载器Class Loader加载Student类。 // 加载后,在方法区中就有了Student类的信息 Student s1 = new Student(); s1.name = "徐子峰"; s1.study(); s1.sayHello("江晴"); Student s2 = new Student(); s2.name = "江晴"; s2.study(); s2.sayHello("徐子峰"); } }