Java construct one instance of Certain Class from another instance -
this question has answer here:
- how private variable accessible? 5 answers
i java beginner. test code 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 here this.b = another.b; } public string geta(){ return a; } public string getb(){ return b; } }
my question why test another
can access private variable
directly using .
, rather using geta()
or getb()
method.
the tutorial tells me private variable
can not accessed directly .
private variables cannot accessed different class, here in same class.
Comments
Post a Comment