My getters and setters for my private var - Java
Yello, I have this small little program where one class (passwordDB) acts as a sort of database which stores a private variable called 'password' which can only be accessed through getters and setters. Although it now partly does what I wanted it to do (allow the user to change the value of the private 'password' variable through the 'main class') I came across various issues which confused me. "this.password = x;" would no longer work unless I changed it to "password = x" (so what's the difference?) Also I had to set the private 'password' variable to static and even the getter method to static for all of this to work. Allot of what I have done is all experimental so I just would like an explanation of what is going on and whether I could have done it differently. Later on I plan to have a conditional statement for my setter method which will will specify something along the lines of: if(correctPass() == true){ password = x } boolean 'correctpass' will be set to true within the main class of the if statements once the user has specified the right password. And then the 'passwordDB' class will use the getter method of the main class to know if it should set the password. https://code.sololearn.com/cA30hxme03Yz/#java