创建对象的内存分析

package Demo.oop.APP;

public class Pet {
    //public公用的,都可以调用
    public String name;
    public int age;
    //无参构造
    public void shout(){
        System.out.println("叫了一声");
    }
}

  构造的一个类

package Demo.oop.APP;
//一个项目通常只用一个启动器,也就是只有一个main方法
public class Application {
    public static void main(String[] args) {
        //类:抽象的需要实例化
        //类实例化后会返回一个自己的对象
        //student就是Student类实例化具体实例
        Student xiaoma = new Student();
        Student xiaoran = new Student();//感觉类似C语言里面的结构体
        xiaoma.name = "小马";
        xiaoma.age = 19;
        System.out.println(xiaoma.name);
        System.out.println(xiaoma.age);
        xiaoran.name = "小冉";
        xiaoran.age = 18;
        System.out.println(xiaoran.name);
        System.out.println(xiaoran.age);
        System.out.println("++++++++++++++++++++++");
        demo01 demo01 = new demo01("xaioma");
        System.out.println(demo01.name);
        System.out.println("+++++++++++++++++++++++");
        Pet dog = new Pet();
        dog.name="旺财";
        dog.age=3;
        dog.shout();
        System.out.println(dog.name);
        System.out.println(dog.age);
    }
}

  main方法,

 

启动器

posted @ 2022-05-17 13:28  回忆也交给时间  阅读(18)  评论(0编辑  收藏  举报