我正在为我的java类做一个项目,我无法理解为什么我收到此错误。这是我的代码:
public class address
{
String Street;
String City;
String State;
String Zip;
public address()
{
Street = "";
City = "";
State = "";
Zip = "";
}
public void setStreet(String street)
{
Street = street;
}
public void setCity(String city)
{
City = city;
}
public void setState(String state)
{
State = state;
}
public void setZip(String zip)
{
Zip = zip;
}
public String getStreet()
{
retrun Street;
}
public String getCity()
{
return City;
}
public String getState()
{
return State;
}
public String getZip()
{
return Zip;
}
}
这是我每个员工的地址等级。我们刚刚了解了OOP。这是带有错误的CMD输出:
答案 0 :(得分:2)
错字:
public String getStreet() {
retrun Street; // should be return
}
答案 1 :(得分:1)
retrun
拼写错误。
答案 2 :(得分:1)
您有拼写错误。你在getStreet方法中写了'retrun'而不是'return'。
答案 3 :(得分:1)
我会尝试使用您的IDE生成这种代码。自己打字只会导致拼写错误。
// type two lines
public class Address {
private String street, city, state, zip;
// and use the IDE to generate a constructor
public Address(String street, String city, String state, String zip) {
this.street = street;
this.city = city;
this.state = state;
this.zip = zip;
}
// generate getters and setters
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
}
答案 4 :(得分:1)
你拼错了return
public String getStreet() {
retrun Street; // wrong
}
一定是
public String getStreet() {
return Street; // correct
}