Java中类对象的实例化过程
简单类对象的实例化过程
示例代码:
public class Person{
public Person(){
}
int age = 1;
String name = "zhangsan";
int sex = 0 ;
public void showInfo(){
System.out.println(this.age);
System.out.println(this.name);
System.out.println(this.sex);
}
public void setInfo(int age,String name,int sex){
this.age = age;
this.name = name;
this.sex = sex;
}
}
Person p = new Person(); 的过程如下:
子类对象的实例化过程
示例代码:
public class Person {
public Person() {
}
int age = 1;
String name = "zhangsan";
int sex = 0;
}
public class Student extends Person{
public Student(){
super();
}
String school;
}
Student stu = new Student(); 的过程如下: