What is wrong with my Code in relation to creating a constructor?

前端 未结 3 1376
走了就别回头了
走了就别回头了 2020-12-12 02:59

I am trying to create a Person class, with a constructor that initiates the instance variables with the given parameters, but when a new person object is created through mai

3条回答
  •  情歌与酒
    2020-12-12 03:48

    This is not a constructor; because of void, it's a method.

    public void Person(String first, String middle, String last, String dateOfBirth){
    

    There was no explicit constructor, so the Java compiler created a default, no-arg constructor. That explains the part of the error message that states:

    required: no arguments
    

    Remove the void to turn it into a constructor.

    public Person(String first, String middle, String last, String dateOfBirth){
    

提交回复
热议问题