CS 121 Chapter Notes - Chapter 7: Iterator, Reserved Word

27 views4 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents