Fork me on GitHub

java之简单类对象实例化过程

假设现在有这么一个类:

public class Person{
    public Person(){}
    String name = "tom";
    int age = 1;
    int sex = 0;
    public void showInfo(){
        System.out.println(this.name);
        System.out.println(this.age);
        System.out.println(this.sex);
    }
    public void seInfo(String name, int age, int sex){
        this.name = name;
        this.age = age;
        this.sex = sex;
    }
}

Person p = new Person();

那么整个对象的创建过程如下:

posted @ 2019-12-16 13:59  西西嘛呦  阅读(262)  评论(0编辑  收藏  举报