Jeanne Boyarsky wrote:In the real world, you are correct. In the simplified world of the exam, the singleton is shared more broadly. On the bright side, the real exam tells you how many answers are correct. If it said "choose three", I bet you'd have included F!
No. I think this would be an unacceptable mistake in the question if it happened on the real exam. A singleton simply does not require the instance to be publicly available. Moreover, a method isn't the only way to expose data.
Now, I realise that using a method to return the instance follows encapsulation and all that, but in the case of a singleton I do not think it adds any value.
In my opinion, the best way to expose a singleton instance is with a (public) static final field initialised at declaration.
So that's at least one alternative. I know the exam likes to be vague and tricky, but here I think it is just wrong.