I just started programming, so I'm sorry if you're saying something strange.
I'd like to add a new setName method to the Person class (the getName and getAge methods are defined), but how can I do it without a return value?
java
Person Class (getName and getAge methods are defined)
If is referring to the following conditions:
public class Person {
private String name;
private age;
public String getName() {
return name;
}
public int getAge(){
return;
}
}
The code is as follows:
public class Person {
private String name;
private age;
public String getName() {
return name;
}
public int getAge(){
return;
}
// Additional parts from here
public void setName(String name){
this.name = name;
}
public void setAge(interage){
This.age=age;
}
}
void
indicates no return value.
© 2023 OneMinuteCode. All rights reserved.