how can i create a new String in a get Method?(Java) -
i have code down below. want if there no other person in row getmother method create new string or person first name "eva" , return this. code doesn't work. "null". how can this? pls help
public person getmother() { if (mother == null) { person p = new person("eva"); } return mother; }
you should initialize mother
, not p
:
public person getmother() { if (mother == null) { mother = new person("eva"); } return mother; }
Comments
Post a Comment