Beruflich Dokumente
Kultur Dokumente
7-5:
Polymorphism
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 3
Polymorphism
Overview
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 4
Polymorphism
Review of Inheritance
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 5
Polymorphism
Learn More
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 6
Polymorphism
Inheritance Example
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 7
Polymorphism
Inheritance Example
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 8
Polymorphism
Polymorphism
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 9
Polymorphism
Polymorphism and Nesting Dolls
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 10
Polymorphism
Superclasses and Subclasses
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 11
Polymorphism
Superclass Variables
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 12
Polymorphism
Superclass Variables
When Java code is executed, Java will "open up" to see what
type of object is inside the reference, and call methods that
are of that type.
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 13
Polymorphism
Uncertainty when Referencing Objects
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 14
Polymorphism
Why Not Use an Array of Class Objects?
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 15
Polymorphism
Why Not Use an Array of Class Objects?
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 16
Polymorphism
Object References
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 17
Polymorphism
Overriding Methods from Object
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 18
Polymorphism
Overriding or Redefining Methods
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 19
Polymorphism
Overriding Methods
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 20
Polymorphism
Overriding Methods
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 21
Polymorphism
Java Tutorials on Overriding Methods
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 22
Polymorphism
Overriding toString()
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 23
Polymorphism
Overriding toString()
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 24
Polymorphism
Understanding the Object Model
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 25
Polymorphism
Object Model Goals
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 26
Polymorphism
Polymorphism and Methods
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 27
Polymorphism
Polymorphism and Methods
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 28
Polymorphism
Dynamic Method Dispatch
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 29
Polymorphism
Abstract Classes
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 30
Polymorphism
Abstract Classes
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 31
Polymorphism
Abstract Classes
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 32
Polymorphism
Abstract Classes
Declare as abstract
public. Do not use {}.
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 33
Polymorphism
Abstract Methods
Abstract methods:
Cannot have a method body.
Must be declared in an abstract class.
Must be overridden in a subclass.
This forces programmers to implement and redefine
methods.
Typically, abstract classes contain abstract methods, partially
implemented methods, or fully-implemented methods.
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 34
Polymorphism
Partially Implemented Methods
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 35
Polymorphism
Partially Implemented Methods
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 36
Polymorphism
Partially Implemented Methods
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 37
Polymorphism
Subclassing Abstract Classes
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 38
Polymorphism
Using Final
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 39
Polymorphism
Using Final
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 40
Polymorphism
Using Final
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 41
Polymorphism
Using Final
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 42
Polymorphism
Using Final
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 43
Polymorphism
Triangle Applet Code
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 44
Polymorphism
Triangle Applet Code Explained
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 45
Polymorphism
Triangle Applet Image
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 46
Polymorphism
Terminology
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 47
Polymorphism
Summary
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 48
Polymorphism
Summary
JF 7-5 Copyright 2015, Oracle and/or its affiliates. All rights reserved. 49
Polymorphism