Polymorphism CSE 115 Spring 2006 March 6, 8 & 10, 2006.

Slides:



Advertisements
Similar presentations
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
Advertisements

Abstract Classes and Interfaces The objectives of this chapter are: To explore the concept of abstract classes To understand interfaces To understand the.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Exam Objective : Demonstrate the use of polymorphism PRESENTED BY: SRINIVAS VG.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics (inheritance review + Java generics)
Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
CSE 115 Week 10 March , Announcements March 21 – Lab 7 Q & A in lecture March 21 – Lab 7 Q & A in lecture March 26 – Exam 7 March 26 – Exam.
Week 9 Recap CSE 115 Spring Collections “Buckets” that can help us carry around large numbers of objects. “Buckets” that can help us carry around.
Week 4 Recap CSE 115 Spring Formal Parameter Lists Comma-separated list of formal parameters Formal parameters are listed giving the type of the.
Week 7 Recap CSE 115 Spring Not a Holder, but a Proxy be We actually wanted to build a Proxy for our program What is the difference? Holder is a.
Command Pattern Chihung Liao Cynthia Jiang. Waiter Order Execute() Hamburger Execute() Hot Dogs Execute() Fries Execute() Cook Make Food()
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 24: Dynamic Binding COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos.
CSE 115 Week 6 February , Announcements Software Installation Fest – Take 2 Software Installation Fest – Take 2 –Tuesday 2/ –Wednesday.
UML Class Diagram: class Rectangle
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2007.
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
CS 106 Introduction to Computer Science I 04 / 23 / 2010 Instructor: Michael Eckmann.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
Lecture 12 March 16, The Scope of a Variable What if there are two variables with the same name? –A local or block-local variable can have the same.
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
CS 106 Introduction to Computer Science I 04 / 18 / 2008 Instructor: Michael Eckmann.
Inspired by the Oulipu. The 3 Tenets of OO Encapsulation Polymorphism Inheritance.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
Inheritance and Polymorphism. Superclass and Subclass Inheritance defines a relationship between objects that share characteristics. It is a mechanism.
Peyman Dodangeh Sharif University of Technology Fall 2014.
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Polymorphism in Methods
Object-Oriented Design
Advanced Programming in Java
Advanced Programming in Java
Advanced Programming in Java
Interface, Subclass, and Abstract Class Review
One class is an extension of another.
Testing Object-Oriented Software Concepts and Definitions
Clicker quiz 10/1/13 CSE 1102 Fall 2013.
Types of Programming Languages
Recitation 6.
UML Class Diagram: class Rectangle
Interfaces and Inheritance
Introduction to Object-oriented Program Design
3 Fundamentals of Object-Oriented Programming
Chapter 10 Thinking in Objects
Interfaces.
One class is an extension of another.
Advanced Java Topics Chapter 9
Polymorphism CT1513.
Advanced Java Programming
CSE 1030: Implementing GUI Mark Shtern.
Abstract Classes Page
Advanced Programming in Java
Chapter 7 Polymorphism.
Polymorphism Polymorphism - Greek for “many forms”
Advanced Programming in Java
Notes from Week 5 CSE 115 Spring 2006 February 13, 15 & 17, 2006.
Presentation transcript:

Polymorphism CSE 115 Spring 2006 March 6, 8 & 10, 2006

A Variable Declaration… Bird bird = new Duck();  Can we do this? Only if Duck is a subclass of Bird or if Duck is a class that implements the Bird interface.

A Variable Declaration… Bird bird = new Duck();  Bird is the declared type of the variable bird  Duck is the actual type of the variable bird

Subtype Polymorphism  Objects of the subclass can be provided to stand in for objects of the superclass.

Polymorphism  When there is a difference between the declared type and actual type of an object, the only methods that can be called are those that are declared in the declared type. The methods that get executed are those in the actual type.

Examples  Flyer-Bird-Duck-Penguin example  Began start/stop bouncing ball example