I want to have a setter and getter
for root word by passing and returning an object of type Word
:
class Master {
Word word = new Word();
word.setName("eating");
word.setRootWord(new Word("eat"));
System.out.println(word.getRootWord().toString());
}
class Word {
private String name;
private Word rootWord, synonyms, antonyms;
public Word () {
}
public Word (String name) {
this.name = name;
}
public setName (String name) {
this.name = name;
}
public getName () {
return this.name;
}
public setRootWord (Word rootWord) {
this.rootWord = rootWord;
}
public getRootWord () {
return this.rootWord;
}
}
What gets printed is something like Word@42a57993
How can I get eat
printed on the screen? or a better way of doing this?