CS 121 Chapter Notes - Chapter 7: Iterator, Reserved Word
Document Summary
Interfaces*: a collection of method headers & constants. An interface uses a set of method headers to define a particular characteristic, if a class needs a characteristic, that class has to implement all these methods. method header public int getage() method body {return age;} We can compare two circles as: if (c1. compareto(c2) < 0) The string class implements comparable, based on the dictionary order. It"s up to the programmer to determine what makes one object less than another. Being able to compare 2 objects is a characteristic. You might need to compare 2 objects of other classes, such as 2 circles, 2 students, 2 rectangles in the same mechanism. A: an interface is used to establish a set of methods (the common characteristic) that a class will implement. The comparable interface: any class can implement comparable to provide a mechanism for comparing objects of that type.