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

时间:2022-07-23
本文章向大家介绍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();

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