Inheritance & Polymorphism Android Club 2015. Agenda Inheritance Polymorphism.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Constructors Method Overriding & Overloading Encapsulation.
Advertisements

Inheritance. Many objects have a hierarchical relationship –Examples: zoo, car/vehicle, card game, airline reservation system Inheritance allows software.
Reusable Classes.  Motivation: Write less code!
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Chapter 8 Improving Structure with Inheritance. The DoME Example The Database of Multimedia Entertainment We will be storing information about CDs and.
SE-1020 Dr. Mark L. Hornick 1 Inheritance and Polymorphism: Abstract Classes The “not quite” classes.
OBJECT-ORIENTED PROGRAMMING CONCEPTS (Review). What is an Object? What is an Object? Objects have states and behaviors. Example: A dog has states - color,
C HAPTER 7 Better Living in Objectville. O VERVIEW Understanding Inheritance Designing an Inheritance Tree Avoiding Duplicate Code Overriding Methods.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
LECTURE 07 Programming using C# Inheritance
CS10092 : Inheritance in Java (#2 of 4) Gavin Brown
Inheritance using Java
Polymorphism & Interfaces
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Java Inheritance.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Inheritance, Abstract & Interface Pepper With help from and
Inheritence Put classes into a hierarchy derive a new class based on an existing class with modifications or extensions. Avoiding duplication and redundancy.
OOP Android Club DO NOT REMEMBER! TRY TO UNDERSTAND!
ECE 122 March 24. Motivation I am tasked to write two classes, one for cat, one for sheep. That is easy. I roll up my sleeve and get it done!
These materials where developed by Martin Schray. Please feel free to use and modify them for non-commercial purposes. If you find them useful or would.
28-Dec-04polymorhism.ppt1 Polymorphism. 28-Dec-04polymorhism.ppt2 signatures in any programming language, a signature is what distinguishes one function.
Parameters… Classes Cont Mrs. C. Furman October 13, 2008.
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 17.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
Encapsulation, Inheritance, Composition. Class Methods Can be either void or return Can have parameters or not Must be static Should be public Know how.
AD Lecture #1 Object Oriented Programming Three Main Principles 1 Inheritance Encapsulation Polymorphism.
CS1101 Group1 Discussion 6 Lek Hsiang Hui comp.nus.edu.sg
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
(c) University of Washington05-1 CSC 143 Java Abstract Classes and Frameworks Reading: Ch. 11.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
Coming up Which methods are where? – Overriding Calling super’s methods Coupling and cohesion.
Comp1004: Inheritance II Polymorphism. Coming up Inheritance Reminder Overriding methods – Overriding and substitution Dynamic Binding Polymorphism –
Comp1004: Object Oriented Design I Abstract Classes and Interfaces.
Modern Programming Tools And Techniques-I
Web Design & Development Lecture 9
Advanced Programming in Java
Advanced Programming in Java
Lecture 12 Inheritance.
Interface, Subclass, and Abstract Class Review
Interfaces.
Inheritance and Polymorphism
Week 14 - Monday CS 121.
Week 4 Object-Oriented Programming (1): Inheritance
Week 8 Lecture -3 Inheritance and Polymorphism
Chapter 10 Thinking in Objects
MSIS 670 Object-Oriented Software Engineering
Inheritance, Polymorphism, and Interfaces. Oh My
Polymorphism and access control
Week 6 Object-Oriented Programming (2): Polymorphism
Advanced Programming Behnam Hatami Fall 2017.
Encapsulation Inheritance PolyMorhpism
CS18000: Problem Solving and Object-Oriented Programming
Advanced Programming in Java
Inheritance Inheritance is a fundamental Object Oriented concept
Chapter 11 Inheritance and Polymorphism
Java Inheritance.
Advanced Programming in Java
Object Oriented Programming
Chapter 9 Carrano Chapter 10 Small Java
Chapter 11 Inheritance and Encapsulation and Polymorphism
Topics OOP Review Inheritance Review Abstract Classes
Presentation transcript:

Inheritance & Polymorphism Android Club 2015

Agenda Inheritance Polymorphism

WHY to use inheritance? CODE REUSE

Inheritance

Inheritance: example public class Bike { int wheel; public Bike() { this.wheel = 2; } public int getWheel() { return wheel; } public void setWheel(int wheel) { this.wheel = wheel; } }

Inheritance: example public class MountainBike extends Bike{ public MountainBike() { super(); }

Inheritance: example public class KidBike extends Bike{ public KidBike() { setWheel(3); }

Inheritance: practice Create super class: Transport Create variables: int wheel + getter&setter Default wheels number should be 4 Create sub-class: Car Create Car constructor: inside call Transport constructor Create sub-class: Boat Set wheel 0

Polymorphism Two objects respond to the same message with different behaviors; the sender doesn't have to care. Steven A. Lowe Peter Mortensen

Polymorphism There are: 2 objects Message: makeNoise Cat: meow Dog: wow Sender does not care

Polymorphism: Animal public class Animal { public String getNoise() { return null; }

Polymorphism: Cat public class Cat extends Animal{ public String getNoise() { return "Meow"; }

Polymorphism: Dog public class Dog extends Animal{ public String getNoise() { return "Wow"; }

Polymorphism: main Animal animal1 = new Cat(); System.out.println(animal1.getNoise()); Animal animal2 = new Dog(); System.out.println(animal2.getNoise());

Polymorphism: practice Create super-class: Zombie Create method: eat Return: void

Polymorphism: practice Create sub class: GardenZombie Create method: eat “Eats 5 pieces”

Polymorphism: practice Create sub class: Gargantua Create method: eat Print “Eats 10 pieces”

Polymorphism: practice Declare Zombie zombieOne Initialize it as GardenZombie Make zombieOne eat Declare Zombie: zombieTwo Initialize it as Gargantua Make zombieTwo eat

Questions? Any questions?

Review Chapter 10: Working with Inheritance and Polymorphism Interface

Thank you! Thank you very much for your attention!