Java Java Objects Delivering the MVP Determining If the Game is Won

gene c
gene c
13,629 Points

doesn't the public method to get the answer defeat the purpose of a private answer variable

Is there a way for only the prompter.java file to access the private answer variable? if not, anyone can access and get the answer with the public getAnswer() method.

1 Answer

Steven Parker
Steven Parker
182,492 Points

The primary benefit of of the private variable isn't to prevent other code from reading it (since as you observed, there's a public method for that); but it's to prevent any other code from changing that value.