有如下代码,请教为什么我用构造方法的重载在对象属性私有化的情况下也能完成创建对象,而使用默认的构造方法时就得在Persion类里使用get和set方法呢
public class Persion1 {
private int age;
private String name;
private String banji;
public Persion1(int age,String name,String banji){
this.age=age;this.name=name;this.banji=banji;
}
public Persion1() {
}
public void show(){
System.out.println(name+"的年龄是"+age+"所在班级是"+banji);
}
}
public class TestPersion1 {
public static void main(String[] args) {
Persion1 xiaohong=new Persion1(18,"小红","三班");
Persion1 xiaoming=new Persion1();
xiaoming.name="小明"; 这个地方报错呢