I am a java beginner. My test code like this:
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;
}
}
My question is why Test another
can access the private variable
directly using .
, rather than using the getA()
or getB()
method.
The tutorial tells me that private variable
can not be accessed directly by .