TAM
TAM

Reputation: 347

The Method is not applicable for the arugment

I get the error mentioned in the title with the following very simple code, and I am not sure what the problem is, I know it is most likely a very simple fix but it has been so long since I done coding I can't bring anything to mind.

s1.setaddress("31 Main street");

that is the snippet that shows the error and the code that I think affects this is from the student class first then the second snippet will be master class person

@Override
public String getaddress() {
    // TODO Auto-generated method stub
    return address;
}
@Override
public String setaddress() {
    return address;
}

person class

public abstract class Person {
protected String name;
protected String surname;
protected String address;
protected int age;

public abstract String getName();
public abstract String getsurName();
public abstract String getaddress();

public abstract String setName();
public abstract String setsurName();
public abstract String setaddress();
public abstract int age();

public String toString(){
    // TODO Auto-generated method stub
    return "Name: " + name + " " + surname + "Age: " + age + "\n"  + "Address: " + address;
};

thanks for any help

Upvotes: 0

Views: 76

Answers (3)

user2030471
user2030471

Reputation:

Your setAddress should accept an argument which modifies the address field:

@Override
public String setaddress(String address) {
    this.address = address;
}

As this is an overridden method, you need to have the same signature in the base class too:

public abstract String setaddress(String address);

You can also get rid of the return type String in the above declarations as it has now become useless.

Upvotes: 2

nikis
nikis

Reputation: 11244

Your getaddress() and setaddress() methods are the same, so I think it's just copy-paste typo. Valid setaddress() should be as the following:

@Override
public void setaddress(String address) {
    this.address = address;
}

Don't forget to change return type at the abstract class also.

Upvotes: 1

Tim B
Tim B

Reputation: 41208

Your setAddress method does not accept any parameters but you are trying to call it with a String.

Try:

public void setAddress(String str) {
    this.address=str;
}

Upvotes: 2

Related Questions