COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 20 – Inheritance and Polymorphism in Java Webpage:

Slides:



Advertisements
Similar presentations
More on Classes Inheritance and Polymorphism
Advertisements

Object Oriented Programming with Java
OO Programming in Java Objectives for today: Constructors Method Overriding & Overloading Encapsulation.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 32 – Java Graphical User Interfaces (GUIs) Webpage:
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Chapter 1 Inheritance University Of Ha’il.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 09 – Programming with Java Datatypes and Flow Control.
Intro to OOP with Java, C. Thomas Wu Inheritance and Polymorphism
Department of computer science N. Harika. Inheritance Inheritance is a fundamental Object Oriented concept A class can be defined as a "subclass" of another.
Principles of Computer Programming (using Java) Chapter 10 Subclasses Haidong Xue Summer 2011, at GSU.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Inheritance The objectives of this chapter are: To explore the concept and implications of inheritance Polymorphism To define the syntax of inheritance.
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Polymorphism. Legal assignments Widening is legal Narrowing is illegal (unless you cast) class Test { public static void main(String args[]) { double.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Polymorphism.
Lecture 10: Inheritance Subclasses and superclasses The inheritance chain Access control The Object cosmic superclass The super keyword Overriding methods.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
Polymorphism CSC 171 FALL 2004 LECTURE 15. Reading Read Chapter 9 of Horstmann.
CPSC150 Interfaces Chapter CPSC150 Inheritance Review No different than any other class. Has no access to or information about subclasses class.
CS 106 Introduction to Computer Science I 04 / 21 / 2010 Instructor: Michael Eckmann.
CSC 111 Course orientation
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Ruby (on Rails) CSE 190M, Spring 2009 Week 4. Constructors Writing a new class is simple! Example: class Point end But we may want to initialize state.
LECTURE 07 Programming using C# Inheritance
CS 106 Introduction to Computer Science I 04 / 13 / 2007 Friday the 13 th Instructor: Michael Eckmann.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 13 – Having Fun with Arrays in Java Webpage:
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Java Inheritance.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Object Oriented Programming Examples: C++, Java Advantages: 1. reusibility of code 2. ability to adapt (extend) previously written code.
Computer Science [3] Java Programming II - Laboratory Course Lab 1 + 2: Review inheritance & abstract Review inheritance & abstractPolymorphism Faculty.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 10 – Programming with Java Datatypes Type Casting.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 13 Inheritance and Polymorphism.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 35 – Overview of Java Web Programming Webpage:
LECTURE 9: INTERFACES & ABSTRACT CLASSES CSC 212 – Data Structures.
CS 160: Software Engineering October 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
JAVA COURSE 1 Computer Engineering Association. Compile your first program Public class Hello{ public class Hello(){ System.out.println(“Hello”); } puclic.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 11 – How to Get Started on Assignment #2 Webpage:
Object Oriented Programming (FIT-II) J. H. Wang Jan. 31, 2008.
Inherited Classes in Java CSCI 392 Ch 6 in O’Reilly Adapted from Dannelly.
CPRG 215 Introduction to Object-Oriented Programming with Java Module 3- Introduction to Object Oriented Programming concepts Topic 3.4 Constructors, Overloading,
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
AD Lecture #1 Object Oriented Programming Three Main Principles 1 Inheritance Encapsulation Polymorphism.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 06 – Java Datatypes Webpage:
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 39 – Command Line Args & Recursion Webpage:
COME 339 WEEK 1. Example: The Course Class 2 TestCourceRunCourse.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 14 – How to Complete Assignment 2, Part III Webpage:
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 08 – Hand-On Work: Assignment 1, Part III Webpage:
Computer Science I ISMAIL ABUMUHFOUZ | CS 180. CS 180 Description BRIEF SUMMARY: This course covers a study of the algorithmic approach and the object.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Programming in Java: lecture 7
Modern Programming Tools And Techniques-I
COP2800 – Computer Programming Using JAVA
Objects as a programming concept
CS230 Tutorial Week 3.
Chapter 10 Thinking in Objects
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Advanced Java Programming
Object-Oriented Programming
Abstract Classes Page
Chapter 11 Inheritance and Polymorphism
Object Oriented Programming (OOP) LAB # 9
Object Oriented Programming
CS Problem Solving and Object Oriented Programming Spring 2019
COP2800 – Computer Programming Using JAVA
Presentation transcript:

COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 20 – Inheritance and Polymorphism in Java Webpage:

COP2800 – Programming in JAVA Course Objectives – Basic Knowledge of Computers & Programming – Specific Knowledge of JAVA Programming – Practical Programming Projects Build Skills Today’s Class – Review of Inheritance Concept(s) – Polymorphism What is Polymorphism, and How is it Used? Polymorphism in Java

Review: Java Program Structure HIGH-LEVEL VIEW JAVA Units: -Packages -Classes (Instances) -Methods -Instructions -Variables PICTURE CREDIT:

Review: Java Package Structure PICTURE CREDIT:

Example: String greeting = "Hello world!"; Review: Classes and Objects CLASS NAME: StringVARIABLE NAME: greeting OBJECT #1OBJECT #2OBJECT #n... Instance-of CLASS DESCRIPTION Instance-of

Example: class Golfer extends Person; Review: Inheritance SUBCLASS NAME: GolferSUPERCLASS NAME: Person... extends SUPERCLASS DESCRIPTION extends SUBCLASS #1 DESCRIPTION SUBCLASS #2 DESCRIPTION SUBCLASS #n DESCRIPTION

Example: Review: Inheritance... extends SUPERCLASS PERSON extends SUBCLASS #1 GOLFER SUBCLASS #2 STUDENT SUBCLASS #n ELECTRICIAN Subclass Variables: swing stance grip score Subclass Variables: gpa health_status major extracurriculars Subclass Variables: availability hourly_rate company unionized... ADD NEW PROP- ERTIES

New Concept: Polymorphism Meaning: Poly = many Morph = shape Example: “+” operator can do many things int + intinteger addition int + floatdecimal addition string + stringconcatenation

Polymorphism (cont’d) NEW WORD: Overloading Example: int + intinteger addition int + floatdecimal addition string + stringconcatenation We say the “+” operator is overloaded because one operator performs many functions

Polymorphism (cont’d) Polymorphism in programming: Strategies: 1 – Write many functions to do many things 2 – Write one polymorphic function to do many things OBJECT- ORIENTED DESIGN

Polymorphism (cont’d) Write one function to do many things (cont’d) Example: length() method Class #1 … length method specification… Class #2 … length method specification…

Polymorphism (cont’d) JAVA: One function to act on many objects Example: length() method Class #1 object1 = Class #2 object2 = object.length

This Week: Inheritance & Polymorphism READING ASSIGNMENT: D. Liang: Chapter 10 (Thinking in Objects) and Chapter 11 (Inheritance and Polymorphism) Wednesday 27 Feb 2013: More on Inheritance & Polymorphism in JAVA Coding Examples Friday 01 Mar 2013: How to do Assignment #3, Part III (LAPTOPS)