Download presentation
Presentation is loading. Please wait.
1
Recitation 8 October 14, 2011
2
Today’s Goals: Overriding versus overloading a method
3
Notes Show off your work!
Record what you have done using screen video capture software Upload to YouTube Send a link to comp401-help Doesn’t replace screenshots Not Graded
4
Extending the Object class
All classes extend the Object class either directly or indirectly
5
Overloading overloaded methods: appear in the same class or a subclass
have the same name but, have different parameter lists, and, can have different return types [Java Quick Reference]
6
Overloading Object equals()
public boolean equals(Example otherExample) { if (otherExample != null) { return (this.getX() == otherExample.getX() && this.getY() == otherExample.getY()); } else return false; equals defined in Example & Object
7
Overriding Overridden methods: appear in subclasses
have the same name as a superclass method have the same parameter list as a superclass method have the same return type as a superclass method A few other conditions you’ll learn later. [Java Quick Reference]
8
Overriding Object equals()
public boolean equals(Object obj) { if(obj instanceof Example && obj != null) { Example otherObj = (Example)obj; return (this.getX() == otherObj.getX() && this.getY() == otherObj.getY()); } else return false; equals defined in Example
9
Overriding & Overloading Object equals()
10
Recitation Specification
Add equals(…) to CartesianLine which overloads Object.equals() Add equals(…) to CartesianTriangle which overrides Object.equals() Bonus (for candy): Make equals work in a graphical sense.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.