具体代码如下: public class CallingConstructorFromConstructor {
//已经声明了是private;
private int i = 0;
//已经声明了是private;
private String show = null;
public CallingConstructorFromConstructor(){
this(10 , "I love this game!");
}
public CallingConstructorFromConstructor(int i , String show){
this.i = i;
this.show = show;
Print();
}
//已经声明了是private;
private void Print(){
System.out.println("i = " + i + " show = " + show);
}
public static void main(String[] args) {
CallingConstructorFromConstructor cc = new CallingConstructorFromConstructor();
//???这里居然可以直接访问并修改;
cc.i = 20;
cc.show = "I hate this game!";
cc.Print();
}
}在JBuilder2005中显示的结果是:
i = 10 show = I love this game!
i = 20 show = I hate this game!
不是private ,外部是部可见的吗?
这里是怎么回事,请高手赐教!谢谢!
//已经声明了是private;
private int i = 0;
//已经声明了是private;
private String show = null;
public CallingConstructorFromConstructor(){
this(10 , "I love this game!");
}
public CallingConstructorFromConstructor(int i , String show){
this.i = i;
this.show = show;
Print();
}
//已经声明了是private;
private void Print(){
System.out.println("i = " + i + " show = " + show);
}
public static void main(String[] args) {
CallingConstructorFromConstructor cc = new CallingConstructorFromConstructor();
//???这里居然可以直接访问并修改;
cc.i = 20;
cc.show = "I hate this game!";
cc.Print();
}
}在JBuilder2005中显示的结果是:
i = 10 show = I love this game!
i = 20 show = I hate this game!
不是private ,外部是部可见的吗?
这里是怎么回事,请高手赐教!谢谢!
别的类的main当然不能访问CallingConstructorFromConstructor的i。