用Object类 判断账号密码是否相同
get,set,必须使用
public class Account { private Object username; private Object password; public Object getUsername() { return username; } public void setUsername(Object username) { this.username = username; } public Object getPassword() { return password; } public void setPassword(Object password) { this.password = password; } public boolean isSame(Account other) { return this.username.equals(other.getUsername()) && this.password.equals(other.getPassword()); } }
Account myAccount = new Account(); myAccount.setUsername("myUserName"); myAccount.setPassword("myPassword");
Account otherAccount = new Account(); otherAccount.setUsername("myUserName"); otherAccount.setPassword("myPassword"); if (myAccount.isSame(otherAccount)) { System.out.println("The username and password are the same."); } else { System.out.println("The username and password are different."); }