所以这是我的代码中包含构造函数的部分。如您所见,目的是让构造函数接受更少的参数并调用最具体的构造函数。我以为我在第一个构造函数中启动了我的值。为什么找不到我的符号?
这是我的代码:
public class Frog{
// instance variables
private String name;
private int age;
private double tongueSpeed;
private boolean isFrogLet;
private String species;
**// Third constructor**
public Frog( String Name){
this(Name, Age, TongueSpeed, IsFrogLet, Species);
}
**//second constructor**
public Frog(String Name, int ageInYears, double TongueSpeed){
this(Name, Age, TongueSpeed, IsFrogLet, Species);
name= Name;
age = ageInYears;
tongueSpeed= TongueSpeed;
}
**// most specific constructor**
public Frog( String Name, int age, double TongueSpeed, boolean IsFrogLet, String Species){
name = Name;
this.age = Age;
tongueSpeed = TongueSpeed;
isFrogLet= IsFrogLet;
species = Species;
}
public void grow(int months){
age = age + months;
while ( age < 12){
tongueSpeed++;
}
if (age>5 & age>30){
double highRes= age-30;
tongueSpeed= tongueSpeed-highRes;
}
if (age>1 & age <7){
isFrogLet = true;
}
}
}
- 这是我得到的错误:
Frog.java:12: error: cannot find symbol
this(Name, Age, TongueSpeed, IsFrogLet, Species);
^
symbol: variable Age
location: class Frog
Frog.java:12: error: cannot find symbol
this(Name, Age, TongueSpeed, IsFrogLet, Species);
^
symbol: variable TongueSpeed
location: class Frog
Frog.java:12: error: cannot find symbol
this(Name, Age, TongueSpeed, IsFrogLet, Species);
^
symbol: variable IsFrogLet
location: class Frog
Frog.java:12: error: cannot find symbol
this(Name, Age, TongueSpeed, IsFrogLet, Species);
^
symbol: variable Species
location: class Frog
Frog.java:19: error: cannot find symbol
this(Name, Age, TongueSpeed, IsFrogLet, Species);
^
symbol: variable Age
location: class Frog
Frog.java:19: error: cannot find symbol
this(Name, Age, TongueSpeed, IsFrogLet, Species);
^
symbol: variable IsFrogLet
location: class Frog
Frog.java:19: error: cannot find symbol
this(Name, Age, TongueSpeed, IsFrogLet, Species);
^
symbol: variable Species
location: class Frog
Frog.java:28: error: cannot find symbol
this.age = Age;
^
symbol: variable Age
location: class Frog