2
我是一個java初學者。我的測試代碼:Java從另一個實例構造某個類的一個實例
public class Test {
private String a;
private String b;
public Test(String a, String b){
this.a = a;
this.b = b;
}
public Test(Test another){
this.a = another.a;//My question comes from here
this.b = another.b;
}
public String getA(){
return a;
}
public String getB(){
return b;
}
}
我的問題是,爲什麼Test another
可以直接使用.
,而不是使用getA()
或getB()
方法訪問private variable
。
的教程告訴我,private variable
不能直接通過.
謝謝。我從你的鏈接中得到了答案。 – Gemsnail