函数初始化有显示初始化和隐式初始化,如果初始化调用的是就是空参数构造函数,是不是只初始化了一次,显示和隐式初始化合二为一了?
class Person
{
//定义一个构造函数。
/**/
Person()
{
System.out.println("person run");
}
//Person(){}
void show()
{
System.out.println("show run");
}
}
class PersonDemo
{
public static void main(String[] args)
{
Car c = new Car();
c.show();
Car c1 = new Car(6);
c1.show();
c1.setNum(8);
c1.show();
}
}
class Car
{
private int num;
Car()
{
num = 4;
}
Car(int a)
{
num = a;
}
public void setNum(int a)
{
num = a;
}
public int getNum()
{
return num;
}
public void show()
{
System.out.println("num="+num);
}
} |
|