constructor not accepting my information

前端 未结 5 1836
长发绾君心
长发绾君心 2021-01-28 08:32

so the constuctor is saying ) expected, error not a statement and ; expected

    Person num1, num2, num3;
    num1=new Person(Allison, 6600 Crescent Ave, 32, 902         


        
相关标签:
5条回答
  • 2021-01-28 09:18

    Step 1:

    First you can check your Person class object is created.

    Print some message in

     public Person() {
          System.out.println("in default constructor");
     }
    

    if you can not see any print statement then problem with object.

    Step 2:

    Check what you pass and passed value is print or not.

    If not print then problem with your parameter(argument).

    Your Problem:

    You are not passing actual string value,You have to pass string value wihin ""

    num1=new Person("Allison", "6600 Crescent Ave", 32, 9024231421);
    

    Many SO user give actually answer but this stuff is for feature reader so user can see and don't take mistake next time.

    0 讨论(0)
  • 2021-01-28 09:21
    num1=new Person(Allison, 6600 Crescent Ave, 32, 9024231421);
    

    should be

    num1=new Person("Allison", "6600 Crescent Ave", 32, 9024231421);
    

    String, String, int and long are expected in this order by your constructor, which is defined by public Person(String nm, String adr, int ag, long phn).

    Allison without (double)quotes is not a String.

    0 讨论(0)
  • 2021-01-28 09:22

    You are not passing a string for Name and Address to your constructor, try changing

    num1=new Person(Allison, 6600 Crescent Ave, 32, 9024231421);
    

    to

    num1=new Person("Allison", "6600 Crescent Ave", 32, 9024231421);
    
    0 讨论(0)
  • 2021-01-28 09:22

    Because strings are always used within the double quotes . put your arguments which are strings in the double quotes.

    0 讨论(0)
  • 2021-01-28 09:24

    you are calling construtor that in not exist for your first argument you have defined string so pass in double quote while calling construtor

    0 讨论(0)
提交回复
热议问题