C HAPTER 8 Serious Polymorphism. O VERVIEW When to not instantiate Abstract Classes Abstract Methods Class Object Casting and Object reference Multiple.

Slides:



Advertisements
Similar presentations
Object Oriented Programming with Java
Advertisements

OOP Abstraction Classes Class Members: Properties & Methods Instance (object) Encapsulation Interfaces Inheritance Composition Polymorphism Using Inheritance.
Classes and SubClasses Super Parent Sub Child IS - A.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
Inheritance and Polymorphism CS180 Fall Definitions Inheritance – object oriented way to form new classes from pre-existing ones –Superclass The.
C8: Understanding Inheritance. Intuitive description Intuitive: FLORISTS are SHOPKEEPERS, inheriting various shopkeeper behaviors Tension in OOP languages:
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.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Prototype Design Pattern A Creational design pattern.
INF 523Q Chapter 7: Inheritance. 2 Inheritance  Another fundamental object-oriented technique is called inheritance, which enhances software design and.
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.
CS 106 Introduction to Computer Science I 11 / 28 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
1 Evan Korth New York University abstract classes and casting Professor Evan Korth New York University.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
UML Class Diagram: class Rectangle
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
GETTING INPUT Simple I/O. Simple Input Scanner scan = new Scanner(System.in); System.out.println("Enter your name"); String name = scan.nextLine(); System.out.println("Enter.
Advanced Inheritance Concepts. In this chapter, we will cover: Creating and using abstract classes Using dynamic method binding Creating arrays of subclass.
9/4/2015Abstract classes & Interface1 Object Oriented Design and Programming II Chapter 10 Abstract classes and Interfaces.
Inheritance using Java
COP 3003 Object-Oriented Programming - Polymorphism Dr. Janusz Zalewski, Fall 2013 Prepared by Dr Dahai Guo.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Polymorphism & Interfaces
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
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.
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Inheritance and Access Control CS 162 (Summer 2009)
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
1 The finalize, clone, and getClass Methods  The finalize method is invoked by the garbage collector on an object when the object becomes garbage.  The.
I NTRODUCTION TO PROGRAMMING Starting Out with Java: From Control Structures through Objects.
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 Inheritance is the process of extending the functionality of a class by defining a new class that inherit,all the features of extending class.
(c) University of Washington06-1 CSC 143 Java Inheritance Tidbits.
CSI 3125, Preliminaries, page 1 Inheritance. CSI 3125, Preliminaries, page 2 Inheritance Using inheritance, can create a general class that defines traits.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
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.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Class Inheritance Part II: Overriding and Polymorphism Corresponds with Chapter 10.
Advanced Programming in Java
Advanced Programming in Java
One class is an extension of another.
abstract classes and casting objects
UML Class Diagram: class Rectangle
One class is an extension of another.
Polymorphism CT1513.
Advanced Programming Behnam Hatami Fall 2017.
Advanced Java Programming
Abstract Classes Page
Chapter 11 Inheritance and Polymorphism
Java Inheritance.
Advanced Programming in Java
Advanced Inheritance Concepts
Presentation transcript:

C HAPTER 8 Serious Polymorphism

O VERVIEW When to not instantiate Abstract Classes Abstract Methods Class Object Casting and Object reference Multiple Inheritance Problem Interfaces

W HEN TO NOT INSTANTIATE Sometimes a superclass is so generic as to be pointless to instantiate This is not bad because the framework for the sub classes is still created For example, creating a new object of type animal is pointless if in ALL other subclasses all properties are overridden

A BSTRACT C LASSES A class can be protected from instantiation by the abstract command This prevents a new object instance to be created. You can still make a reference variable however

A BSTRACT M ETHODS Abstract classes can still have inheritable methods To make sure that subclasses must write their own methods, individual methods can be made abstract This can only be done in abstract classes

C LASS O BJECT There is the mother of all superclasses, class Object Every class by default inherits directly or indirectly from class Object Some Object methods: equals() getClass() hashCode() toString()

C ASTING AND O BJECT REFERENCE

M ULTIPLE I NHERITANCE P ROBLEM

I NTERFACES