If you already know that question's answer whats the point of asking. Secondly thats pure and basic common sense. If you want to ask from a design perspective then please elaborate on the question with the suitable alternative as to what do we use and why. Your question is too vague to be answered logically.
Set and get methods allow access to private fields without "exposing" those fields. They may weaken encapsulation, but that can be minimised by putting controls in the methods.That version allows no control on which values are passed, nor controls on the use of the "f" reference after it has been returned.This second version ensures the value of i is always in a permitted range, as well as testing f for something or other. In either case, it throws an Exception with a nice error message so you can see what went wrong. You will also see that the returned f is cloned, so any manipulation of the clone does not affect this object.
There are different ways of handling such problems. For example, a copy constructor may be better than cloning. Note that i is a primitive, so there is no need to copy it when it is returned.
Agree with seetharaman venkatasamy that you ought to ask more details and with Samir Kureshi that you posted in the wrong place.
Aditya Keyal and Zandis Murāns: your responses are close to the line separating fair comment from rudeness.
What is that? Is that a mongol hoarde? Can we fend them off with this tiny ad?