![]() |
![]() |
![]() |
![]() |
![]() |
|
As a general rule, you should place instance variables and define methods such that two criteria are satisfied:
For example, the fCalories, cCalories, and pCalories
instance variables are all placed in the Food class, because they
are useful for all Food subclasses, although they are not useful for
classes that are not Food subclasses, such as the Integer,
Float, and Fraction classes. Similarly, various accessors
and the tCalories method are defined for the Food class,
because they are useful for all Food subclasses.