- 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

22nd Jun 2017, 5:37 AM
suryapoojary
suryapoojary - avatar
1 Resposta
+ 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; } } }
22nd Jun 2017, 5:55 AM
Claudiu Stefan Haidu
Claudiu Stefan Haidu - avatar