- 1
Im trying to understand getters and setters in java.
when I try to run this code..I get a undefined symbol error.. please help https://code.sololearn.com/cU2B27d8dDhv/?ref=app
1 Antwort
+ 1
You are missing the name variable/field in the Honnie class.
A class consists of variables/fields and methods that usually act on the variables.
in the method : setName(String n) you wanted to set the "name" variable to the input "n", but the name field was nowhere declared in the Honnie class.
public class Program
{
public static void main(String[] args) {
Honnie ronaldinho = new Honnie();
ronaldinho.getName("Brazil");
}
static class Honnie{
String name;
String getName(String name){
return name;
}
void setName(String n){
name = n;
}
}
}