This is a very simple example of my project which is a lot more bigger in scale.
Tasks:
The password will be set at the setpassword method.
The getpassword method will return the password.
The password is called at sendmail class in order to be send via email to the user to log in with the new credentials.
But When I run the whole code everything works except that the sendmail class won't access the password from the getpassword method in users class.
I put a simple version of my code:
users class >>>>>
public class users {
private String password;
public users (){}
// GETTING PASSWORD
public String getpassword(){
return password;
}
// SETTING PASSWORD
public void setapassword(String password){
this.password=password;
}
}
Signup class>>>>>>
public class signup {
public void signsup(){
users user1 =new users();
user1.setapassword("player");
sendmail mail1 =new sendmail();
mail1.Sendsmail();
}
}
sendmail class>>>>
public class sendmail {
public void Sendsmail(){
users user1 =new users(); // object
user1.getpassword(); //getting password
System.out.println(user1.getpassword()); // If print here I get null
}
}
Main signup Class>>>>
public class SignupMain {
public static void main(String[] args) {
signup signup1= new signup();
signup1.signsup();
}
}
See Question&Answers more detail:os