创建对象及内存分析图

 1 //第一步:编写类
 2 class Student{
 3     //第二步:编写属性也叫做成员变量
 4     String name;        //默认值为null
 5     int age;        //默认值为0
 6     char sex;    //默认值为\u0000
 7     String address;    //默认值为null
 8 
 9     //第三步:编写方法
10     public void study(){
11         System.out.println("正在学习面向对象......");
12     }
13 }
14 //编写学生的测试类
15 class StudentTest{
16     public static void main(String[ ]args){
17         //根据类(本例子是Student类)创建对象 语法格式:类名 引用名称 = new 类名();
18         /*
19             new Student();表示创建一个对象,new的Student,则创建的就是学生对象,同时在堆内存中开辟一块空间
20             将右侧的对象地址赋给左侧引用名称zs 
21         Student zs = new Student();
22     }
23 }

内存分析图:

posted @ 2019-05-21 10:42  Penphy  阅读(418)  评论(0编辑  收藏  举报