I already did some research about this topic (e.g. Difference between constructor and getter and setter). The main difference between getter- and setter-methods and constructor is clear for me. I just want to create a simple login window (without a db in background) but I have some issues with my getter and setter methods.
I created a class called user
and a class called admin
. The user
class has a constructor and getter and setter methods:
public class User {
private String fName;
private String nName;
private String password;
private String username;
private int group;
//Constructor
public User(String username, String fName, String nName, String password, int group){
this.username = username;
this.fName = fName;
this.nName = nName;
this.password = password;
this.group = group;
}
//getter and setter methods here
In an other class I tried to create a new user:
public class Admin extends User{
private String username = "admin";
private String fName = "name";
private String nName = "secondName";
private String password = "password";
private int group = 1;
public Admin(String username, String fName, String nName, String password, int group){
super(username, fName, nName, password, group);
}
User admin = new User(username, fName, nName, password, 1);
}
Now I can't use for example admin.setUsername("admin1");
. Why is this?