Adding a Method to the Box Class

Although it is perfectly fine to create a class that contains only data, it rarely happens, Most of the time you will use methods to access the instance variables defined by the . . class. In fact, methods dcfir e the interface to most classes ..This allows the class implementor to hide the specific layout of intemaldata structuresbehind cleaner· method abstractions, In addition to defining methods that provide access to data, you can also define methods that are used internally by the class itself. " Let's begin by adding a method to the Box class. It may have occurred to you while looking-at the preceding programs that the computation of a box's volume wns something that was best handled by the Box class rather than .the BoxDem'o class, After

Share This