Question: The Fraction class immutable classes In this section, we'll build another Fraction class that is unchangeable once initialized and uses the keyword final for its


The Fraction class immutable classes In this section, we'll build another Fraction class that is unchangeable once initialized and uses the keyword final for its numerator and denominator. Such a Fraction object will have all of its data declared final, and is our first example of building an immutable class. Once a Fraction object is built, its data items will never change for the lifetime of the object. Another way to view this is that the object is completely read-only. As a result, its data will also be declared public, which is the only example of public data you'll find in this quarter. If you wish to change a fraction object's numerator or denominator, the old object must be discarded and a new object created in its place. Again, this object's data will be immutable, constant, non-variable, unchangeable, non-editable, or read-only. So, to add two fractions, our add function will return a new Fraction object that is the sum of the two previous (unchangeable) fractions we wish to add. Once you've built this class, uncomment out the appropriate tests in the driver for this lab. Start by building a new Fraction class, and define the following members
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
