Java construct one instance of Certain Class from another instance -


this question has answer here:

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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -