Recitation 8 October 14, 2011.

Slides:



Advertisements
Similar presentations
Chapter 13 Abstraction and inheritance. This chapter discusses n Implementing abstraction. u extension u inheritance n Polymorphism/dynamic binding. n.
Advertisements

CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 11 / 26 / 2007 Instructor: Michael Eckmann.
== equals ? CSE 331 SOFTWARE DESIGN & IMPLEMENTATION EQUALITY Autumn 2011.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Inheritance and Polymorphism.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
CS 106 Introduction to Computer Science I 11 / 20 / 2006 Instructor: Michael Eckmann.
CS2200 Software Development Lecture: Object class A. O’Riordan, 2008.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 11 / 15 / 2006 Instructor: Michael Eckmann.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
1 Java Object Model Part 2: the Object class. 2 Object class Superclass for all Java classes Any class without explicit extends clause is a direct subclass.
1 Inheritance and Polymorphism. 2 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
CS 106 Introduction to Computer Science I 04 / 21 / 2010 Instructor: Michael Eckmann.
© 2003 Walter Savitch These slides are for the exclusive use of students in CSE 11 at UCSD, Winter quarter They may not be copied or used for any.
Polymorphism. Lecture Objectives To understand the concept of polymorphism To understand the concept of static or early binding To understand the concept.
Inheritance One of the biggest advantages of object-oriented design is that of inheritance. A class may be derived from another class, the base class.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 11 Inheritance and Polymorphism.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Generalized Containers CSIS 3701: Advanced Object Oriented Programming.
Non-static classes Part 2 1. Methods  like constructors, all non-static methods have an implicit parameter named this  for methods, this refers to the.
CS/ENGRD 2110 FALL 2014 Lecture 6: Consequence of type, casting; function equals 1.
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
Polymorphism. 3 main programming mechanisms that constitute OOP: 1. Encapsulation 2. Inheritance 3. Polymorphism.
CS 61B Data Structures and Programming Methodology July 3, 2008 David Sun.
Overriding toString()
Inheritance (Part 2) KomondorBloodHound PureBreedMix Dog Object.
1 COS 260 DAY 19 Tony Gauvin. 2 Agenda Questions? 8 th Mini Quiz not corrected yet 9 Th Mini Quiz next class –Due November 19 Finish Discussion on More.
Peyman Dodangeh Sharif University of Technology Fall 2014.
(c) University of Washington06-1 CSC 143 Java Inheritance Tidbits.
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
1 Object-Oriented Programming Inheritance. 2 Superclasses and Subclasses Superclasses and Subclasses  Superclasses and subclasses Object of one class.
CSC142 NN 1 CSC 142 Overriding methods from the Object class: equals, toString.
Inheritance INHERITANCE: extend existing classes by adding or redefining methods, and adding instance fields Suppose we have a class Vehicle: public class.
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Comp1004: Inheritance II Polymorphism. Coming up Inheritance Reminder Overriding methods – Overriding and substitution Dynamic Binding Polymorphism –
CS/ENGRD 2110 SPRING 2016 Lecture 6: Consequence of type, casting; function equals 1.
Sections Inheritance and Abstract Classes
Searching.
Advanced Programming in Java
CSC 205 Java Programming II
Lecture 17: Polymorphism (Part II)
Sorry these slides weren’t available last evening!
CS/ENGRD 2110 Fall 2017 Lecture 6: Consequence of type, casting; function equals
The fattest knight at King Arthur's round table was Sir Cumference
COS 260 DAY 19 Tony Gauvin.
Continuing Chapter 11 Inheritance and Polymorphism
Recitation 6 Inheritance.
Overloading and Constructors
Inheritance, Polymorphism, and Interfaces. Oh My
CS/ENGRD 2110 Fall 2018 The fattest knight at King Arthur's round table was Sir Cumference. He acquired his size from too much pi. Lecture 6: Consequence.
Building Java Programs
CSE 143 Lecture 24 Inheritance and the Object class; Polymorphism
Recitation 7 October 7, 2011.
OO Design with Inheritance
Overriding methods from the Object class: equals, toString
Introduction to Inheritance
Advanced Inheritance Concepts
CS/ENGRD 2110 Spring 2019 Lecture 6: Consequence of type, casting; function equals
CSE 143 Lecture 24 Inheritance and the Object class; Polymorphism
CSE 143 Lecture 24 Inheritance and the Object class; Polymorphism
CSE 143 Lecture 23 Inheritance and the Object class; Polymorphism
Overloading Each method has a signature: its name together with the number and types of its parameters Methods Signatures String toString()
Advanced Programming in Java
Presentation transcript:

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

Extending the Object class All classes extend the Object class either directly or indirectly

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]

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

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]

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

Overriding & Overloading Object equals()

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.