In the Rational class, defined in chapter 4, the methods reduce and gcd are declared to be private. Why?


In the Rational class, defined in chapter 4, the methods reduce and gcd are declared to be private. Why?


a) Because they will never be used

b) Because they will only be called from methods inside of Rational

c) Because they will only be called from the constructor of Rational

d) Because they do not use any of Rational’s instance data

e) Because it is a typo and they should be declared as public

Answer: b. Explanation: All items of a class that are declared to be private are only accessible to entities within that class, whether they are instance data or methods. In this case, since these two methods are only called from other methods (including the constructor) of Rational, they are declared private to promote information hiding to a greater degree. Note that answer c is not a correct answer because the reduce method calls the gcd method, so one of the methods is called from a method other than the constructor.