gpt4 book ai didi

java - 错误实际参数列表和形式参数列表的长度不同

转载 作者:行者123 更新时间:2023-11-30 08:14:35 27 4
gpt4 key购买 nike

constructor Student in class javaapplication 14.Student cannot be applied to given types; required: java.lang.String,int,java.lang.String,java.lang.String,double found: java.lang.String,double reason: actual and formal argument lists differ in length

这是给我错误的行

super(idNum, gpa);

这是我的代码:

package javaapplication14;

public class JavaApplication14
{
public static void main(String[] args)
{
Person bob = new Person("Coach Bob", 27, "M");
System.out.println(bob);

Student lynne = new Student("Lynne Brooke", 16, "F", "HS95129", 3.5);
System.out.println(lynne);
Teacher mrJava = new Teacher("Duke Java",34,"M","Computer Science",50000);
System.out.println(mrJava);
}
}

class Person
{
protected String myName ;
protected int myAge;
protected String myGender;

public Person(String name, int age, String gender)
{
myName = name;
myAge = age ;
myGender = gender;
}

@Override
public String toString()
{
return myName + ", age: " + myAge + ", gender: " +myGender;
}


//These are the set methods
void setName(String name)
{
myName = name;
}

void setAge(int age)
{
myAge = age ;
}

void setGender(String gender)
{
myGender = gender;
}

//These are the get methods
String myName()
{
return myName;
}

int myAge()
{
return myAge;
}

String myGender()
{
return myGender;
}
}


class Student extends Person
{
protected String myIdNum;
protected double myGPA;

public Student(String name, int age, String gender,String idNum, double gpa)
{
super(name, age, gender);
myIdNum = idNum;
myGPA = gpa;
}

//These are the set methods
void setmyIdNum(String idNum)
{
myIdNum = idNum;
}

void setmyGPA(double gpa)
{
myGPA = gpa;
}

@Override
public String toString()
{
return super.toString() + ", student id: " + myIdNum + ", gpa: " + myGPA;
}

public String myIdNum()
{
return myIdNum;
}

double myGPA()
{
return myGPA;
}
}


class Teacher extends Person
{
public double mySalary;
public String mysubjectName;

public Teacher( String name, int age, String gender, String
subjectName,double salary )
{
super(name, age, gender);
mysubjectName = subjectName;
mySalary = salary;
}

//These are the setter methods
void setsubjectname(String subjectName)
{
mysubjectName = subjectName;
}

void setsalary(double Salary)
{
mySalary = Salary;
}

@Override
public String toString()
{
return super.toString() + ", subject name: " + mysubjectName + ", Salary: "
+ mySalary;
}

//These are the getter methods
public String getsubjectname(String subjectName)
{
return subjectName;
}
double getsalary(double Salary)
{
return Salary ;
}

class CollegeStudent extends Student
{
public String myMajor;
public int myYear;

public CollegeStudent(String name, int age,String gender,
String idNum, double gpa, int year, String major )
{
super(idNum, gpa);
myMajor = major;
myYear = year;
}


void setmajor(String Major)
{
myMajor = Major;
}

void setyear(int Year)
{
myYear = Year;
}

@Override
public String toString()
{
return super.toString() + ", major: " + myMajor + ", Year: " + myYear;
}

//These are the getter methods
public String getmajor(String myMajor)
{
return myMajor;
}
public int getyear(int myYear)
{
return myYear ;
}
}
}

最佳答案

Student类中没有这样的带两个参数的构造函数

关于java - 错误实际参数列表和形式参数列表的长度不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29844614/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com