CS102_OOP_2 - CS102OOP_2 Inheritance, Polymorphism,...

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

View Full Document Right Arrow Icon
    CS102 – OOP_2 Inheritance,  Polymorphism,  classes . David Davenport Spring 2002
Background image of page 1

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

View Full DocumentRight Arrow Icon
    Motivation Do not want to include instances of common  (base) class in polymorphic collection May not know how to implement method in  common class, but need guarantee it is  included in all objects of collection
Background image of page 2
    Abstract Classes  Abstract classes provide  common parent which  cannot be instantiated a guarantee sub-classes already have or must implement certain methods Create with keyword “abstract” e.g.  public abstract class Media {…} (sub-class extends abstract class as normal) Can include Properties  Implemented methods Abstract methods  e.g.  public abstract double getDuration();
Background image of page 3

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

View Full DocumentRight Arrow Icon
    The Media Hierarchy Object MusicCD DiscountCD Video Media Library DVD price, title,  getPrice() {abst} getDuration() toString(), clone(), … artist, tracks getDuration() discount getPrice() length director getDuration() Set of Media getValue() getTotalDuration()
Background image of page 4
    The Media Class public abstract class Media { String title; double price; public Media( String title, double price) { this.title = title; this.price = price; } public String getTitle() { return title; } public double getPrice() {return price; } public void setPrice( double newPrice) { price = newPrice; } public abstract int getDuration(); public String toString() { return title + "\t" + getPrice() + "\n";
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/14/2011 for the course CS 102 taught by Professor David during the Spring '08 term at Bilkent University.

Page1 / 18

CS102_OOP_2 - CS102OOP_2 Inheritance, Polymorphism,...

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

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