Object Oriented Programming (OOP) LAB # 9

Slides:



Advertisements
Similar presentations
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Advertisements

OOP: Inheritance By: Lamiaa Said.
Stereotypes Stereotypes provide the capability to create a new kind of modeling element. –They can be used to classify or mark modeling elements. –A type.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
Object–Orientated Design. OOP Design Describe the following: a computer a university Usually the most natural way to describe a task is to list the entities.
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.
Fall 2007ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
CS503: Fourth Lecture, Fall 2008 Advanced OOP and Lab. Michael Barnathan.
Object Oriented Programming (OOP) LAB # 5 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Inheritance Review/Recap. ClassA extends ClassB ClassA now inherits (can access and use) all public and protected elements of ClassB We can expect the.
Object Oriented Programming
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
CSE 501N Fall ‘09 15: Polymorphism October 22, 2009 Nick Leidenfrost.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Ch. 2 Discussion Head First Java. Big Idea Differene between a class and an object What benefit object-oriented programming gives you. Read “Chair Wars”
: Maha Sabri Altememe Lecturer : Maha Sabri Altememe Lecture :1 1.
Object Oriented Programming
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
CS 5JA Introduction to Java Pop Quiz Define/Explain encapsulation. In object-oriented programming, encapsulation refers to the grouping of data and the.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
A Introduction to Computing II Lecture 3: Interfaces and Inheritance Fall Session 2000.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
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.
Object Oriented Programming (OOP) LAB # 3 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
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.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Java Interfaces CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University (see Chapter 9 of.
Class Inheritance Part II: Overriding and Polymorphism Corresponds with Chapter 10.
Object-Oriented Programming
Programming in Java: lecture 7
Modern Programming Tools And Techniques-I
Polymorphism.
Objects First with Java A Practical Introduction using BlueJ
Python First Edition STARTING OUT WITH Chapter 10 Inheritance
Polymorphism, Abstract Classes & Interfaces
OBJECT ORIENTED PROGRAMMING II LECTURE 7 GEORGE KOUTSOGIANNAKIS
OOP What is problem? Solution? OOP
Object Oriented Concepts -II
Week 4 Object-Oriented Programming (1): Inheritance
CS100A Lecture 22 Previous Lecture This Lecture Inheritance
Section 11.1 Class Variables and Methods
Classes in C++ C++ originally called "C with classes":
Object Oriented Programming
3 Fundamentals of Object-Oriented Programming
Chapter 10 Thinking in Objects
Inheritance, Polymorphism, and Interfaces. Oh My
Object Oriented Programming (OOP) LAB # 8
Inheritance, Polymorphism, and Interfaces. Oh My
MSIS 670 Object-Oriented Software Engineering
Classes in C++ C++ originally called "C with classes":
Chapter 9: Polymorphism and Inheritance
Week 6 Object-Oriented Programming (2): Polymorphism
Object Oriented Programming (OOP) LAB # 5
Object-Oriented Programming
Polymorphism, Abstract Classes & Interfaces
Announcements & Review
Software Design Lecture : 12.
Java Programming Course
Chapter 11 Inheritance and Polymorphism
Java Programming, Second Edition
Page 31 A B C D E The following figures above all have the same area, but may have different perimeters. Which of the figures has the smallest perimeter?
An Example of Inheritance
Object Oriented Programming
Final and Abstract Classes
Object-Oriented Programming
Presentation transcript:

Object Oriented Programming (OOP) LAB # 9 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal

Polymorphism

Polymorphism Generally, polymorphism refers to the ability to appear in many forms. Polymorphism in a Java program: The ability of a reference variable to change behavior according to what object instance it is holding. This allows multiple objects of different subclasses to be treated as objects of a single super class, while automatically selecting the proper methods to apply to a particular object based on the subclass it belongs to.

Polymorphism An object reference can refer to an object of its class, or to an object of any class related to it by inheritance. For example, if the Shape class is used to derive a class called Square, then a Shape reference could be used to point to a Square object. Shape Square Shape object= new Square();

Polymorphism Example#1 Let’s consider we have the Shapes class from the previous lecture.

Polymorphism Example#1 Now, we have two subclasses that extend the super class Shape. They are Square and Triangle.

Polymorphism Example#1 Notice the object reference changes its value or take more forms. First, it refers to Square object “s”. Second, it refers to the Triangle object “T”. In each time, it calls the right methods. See the result.

Polymorphism Example#2 Let’s have a super class called Peron and two subclasses extend it. They are Male and Female classes.

Polymorphism Example#2

Polymorphism Example#2 Polymorphism allows you to Create an array of two or more objects and loop through them. The process will be more difficult without polymorphism.

The End !!