ch12 - Java Programming Fourth Edition Chapter 12 Advanced...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Java Programming Fourth Edition Chapter 12 Advanced Inheritance Concepts
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 2 Objectives • Create and use abstract classes • Use dynamic method binding • Use a superclass as a method parameter • Create arrays of subclass objects
Background image of page 2
Java Programming, Fourth Edition 3 Objectives (continued) • Use the Object class and its methods • Use inheritance to achieve good software design • Create and use interfaces • Create and use packages
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 4 Creating and Using Abstract Classes • Abstract class – Cannot create any concrete objects – Can inherit – Usually has one or more empty abstract methods – Use keyword abstract – Provide superclass from which other objects can inherit – public abstract class Animal
Background image of page 4
Java Programming, Fourth Edition 5 Creating and Using Abstract Classes (continued) • Abstract method does not have: – Body – Curly braces – Method statements • To create abstract method – Keyword abstract – Header including method type, name, and arguments – Include semicolon at end of declaration – public abstract void speak();
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 6 Creating and Using Abstract Classes (continued) • Subclass of abstract class – Inherits abstract method from parent • Must provide implementation for inherited method • Or be abstract itself – Code subclass method to override empty superclass method
Background image of page 6
Java Programming, Fourth Edition 7 Using Dynamic Method Binding • Every subclass object “is a” superclass member – Convert subclass objects to superclass objects – Can create reference to superclass object • Create variable name to hold memory address • Store concrete subclass object Animal ref; ref = new Cow();
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 8 Using Dynamic Method Binding (continued) • Dynamic method binding – Also called late binding – Application’s ability to select correct subclass method – Makes programs flexible • When application executes – Correct method attached to application based on current one
Background image of page 8
Java Programming, Fourth Edition 9 The AnimalReference Application
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Using a Superclass as a Method Parameter • Use superclass as method argument – Pass in subclass • Use dynamic method binding public static void talkingAnimal(Animal animal) Dog dog = new Dog(); talkingAnimal(dog);
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/13/2011 for the course 332 351 taught by Professor Staff during the Fall '08 term at Rutgers.

Page1 / 40

ch12 - Java Programming Fourth Edition Chapter 12 Advanced...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online