Undefined constructor (java)

后端 未结 4 892
遇见更好的自我
遇见更好的自我 2021-01-21 23:16

so I have a java class called User that contains a constructor like this:

public class User extends Visitor {
    public User(String UName, String Ufname){
              


        
4条回答
  •  温柔的废话
    2021-01-21 23:30

    You must call the Visitor's constructor on the first like of the constructor that extends the Visitor's class, using super():

    public User(String UName,String Ufname){
        super();
        setName(UName);
        setFname(Ufname);
    }
    

    and if you want Admin to have a custom constructor too, you must call:

    super(uname, ufname) // String, String - pass the params of the superclass cunstructor
    

    So:

    public Admin() {
        super(someString, someString);
    }
    

提交回复
热议问题