public class ModifierTest1{public static void main( String[] args ) {A a = new A();//System.out.println(a.s);a.f();}}class A{private int i;private String s;public A()
{
i = 123;
s = "hello";
}
public void f()
{
A a = new A();
System.out.println(a.i + a.s );
}}這個程序中一共創(chuàng)建了兩個A類的對象,在類A的f()方法中創(chuàng)建的對象a,可以之間用a.i和a.s訪問私有成員變量,而在main函數(shù)中創(chuàng)建的對象卻不可如此使用,有點糊涂了,誰能幫忙解釋下,謝了
添加回答
舉報
0/150
提交
取消