作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Eclipse 一直说构造函数未定义 - 这里出了什么问题?我已经检查了一切。
package exerciseOne;
public class TestCountryClass {
public static void main(String[] args) {
ClassCountry oCon1 = new ClassCountry("Iceland", "Icelandic", "króna", 400000);
System.out.printf("%s %s %d%n", oCon1.getCountryName(),
oCon1.getCountryLanguage(),
oCon1.getCountryCurrency(),
oCon1.getCountryPopulation());
}
}
这是该类的代码,我已经检查了多次,但 Eclipse 一直返回相同的错误消息。我希望你们能够在这里找到问题;感谢任何帮助:
package exerciseOne;
public class ClassCountry {
private String countryName;
private String countryLanguage;
private String countryCurrency;
private int countryPopulation;
public void classCountry(String countryName, String countryLanguage, String countryCurrency, int countryPopulation)
{
this.countryName = countryName;
this.countryLanguage = countryLanguage;
this.countryCurrency = countryCurrency;
this.countryPopulation = countryPopulation;
}
public void setCountryName(String countryName)
{
this.countryName = countryName;
}
public String getCountryName()
{
return countryName;
}
public void setCountryLanguage(String countryLanguage)
{
this.countryLanguage = countryLanguage;
}
public String getCountryLanguage()
{
return countryLanguage;
}
public void setCountryPopulation(int countryPopulation)
{
this.countryPopulation = countryPopulation;
}
public int getCountryPopulation()
{
return countryPopulation;
}
public void setCountryCurrency(String countryCurrency)
{
this.countryCurrency = countryCurrency;
}
public String getCountryCurrency()
{
return countryCurrency;
}
}
最佳答案
public void classCountry(String countryName, String countryLanguage, String countryCurrency, int countryPopulation)
{
this.countryName = countryName;
this.countryLanguage = countryLanguage;
this.countryCurrency = countryCurrency;
this.countryPopulation = countryPopulation;
}
这是你的问题。您已将其添加为构造函数,但这不是构造函数。这是一个返回类型为 void 的方法。
将上面的内容更改为:
public ClassCountry(String countryName, String countryLanguage, String countryCurrency, int countryPopulation)
{
this.countryName = countryName;
this.countryLanguage = countryLanguage;
this.countryCurrency = countryCurrency;
this.countryPopulation = countryPopulation;
}
有关构造函数的更多信息,可以查看这个Oracle tutorial .
关于java - 构造函数 ClassCountry(String, String, String, int) 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52491799/
Eclipse 一直说构造函数未定义 - 这里出了什么问题?我已经检查了一切。 package exerciseOne; public class TestCountryClass { pub
我是一名优秀的程序员,十分优秀!