1 / 10

Recitation 8

Recitation 8. October 14, 2011. Today’s Goals:. Overriding versus overloading a method. 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.

ivory
Download Presentation

Recitation 8

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 booleanequals(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(objinstanceof 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.

More Related