-7

我正在为我的 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 输出:

在此处输入图像描述

4

5 回答 5

2

错字:

public String getStreet()  {
    retrun Street; // should be return
}
于 2012-12-30T16:31:03.783 回答
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;
    }
}
于 2012-12-30T16:34:20.890 回答
1

你拼错了return

public String getStreet()  {
    retrun Street; // wrong
}

肯定是

public String getStreet()  {
    return Street; // correct
}
于 2012-12-30T16:34:30.787 回答
1

retrun​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

于 2012-12-30T16:30:07.500 回答
1

你有一个拼写错误。您在 getStreet 方法中写了 'rerun' 而不是 'return'。

于 2012-12-30T16:30:16.173 回答