Claudio Lopez Claudio Lopez - 5 months ago 6
Java Question

How to implement setters and getters with String and int at the same time?

I know how to "setValue" the "getValue" however how you do "getValue" in this case?

public void setInfo(String name, int age) {
setName(name);
setAge(age);
}


Is there a way to getInfo with string and int at the same time?

Answer

There are multiple ways, one is given below:

public Object[] getInfo() {
    Object[] info = new Object[2];
    info[0] = getName();
    info[1] = getAge();
    return info;
}
Comments