[Current] [News] [Glance] [Search] [Instructions] [Links] [Handouts] [Project] [Outlines] [Labs] [Homeworks] [Quizzes] [Exams] [Examples] [EIJ] [API]
Back to When Things Go Wrong. On to Lab: Java's Abstract Windowing Toolkit.
Held Monday, September 18, 2000
Summary
Today we delve into issues of inheritance, polymorphism, overloading, and overriding by considering how one might write methods that compare objects for equality.
Notes
equals
method that
may help with PartC.
Overview
equals
methods
equals
methodsequals
method defined in the
java.lang.Object
class.
public boolean equals(Object other)
equals
returns true if and only if the
two objects
Fraction
class?
Fraction
equal this fraction?'' method.
/** * Determine if another Fraction is equal to this fraction. * Pre: Both fractions are initialized. * Post: Returns true if both are equal in the sense that they * have the same numerator and denominator. (Not a true * sense of equality, but the best I can come up with for * now.) */ public boolean equals(Fraction other) { return ( (this.numerator == other.numerator) && (this.denominator == other.denominator) ); } // equals(Fraction)
instanceof
.
public boolean equals(Object other) { if (other instanceof Fraction) { return equals((Fraction) other); } else if (other instanceof Integer) { return ( (this.denominator == 1) && ((Integer) other).intValue() == this.numerator); } else { return false; } } // equals(Object)
Wednesday, 23 August 2000
Thursday, 24 August 2000
Monday, 18 September 2000
Tuesday, 19 September 2000
Back to When Things Go Wrong. On to Lab: Java's Abstract Windowing Toolkit.
[Current] [News] [Glance] [Search] [Instructions] [Links] [Handouts] [Project] [Outlines] [Labs] [Homeworks] [Quizzes] [Exams] [Examples] [EIJ] [API]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/2000F/Outlines/outline.14.html
Source text last modified Wed Oct 25 10:05:37 2000.
This page generated on Fri Oct 27 08:19:52 2000 by Siteweaver. Validate this page's HTML.
Contact our webmaster at rebelsky@grinnell.edu