04AbstractClasses

04AbstractClasses - CMSC 132: Object-Oriented Programming...

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

View Full Document Right Arrow Icon
CMSC 132: Object-Oriented Programming II Abstract Classes Department of Computer Science University of Maryland, College Park
Background image of page 1

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

View Full DocumentRight Arrow Icon
Modifier – Abstract Description Leave lower-level details to subclass Defines contract for subclasses Allows inheritance of other methods/data Applied to Methods Classes Example abstract class Foo { // abstract class abstract void bar( ) { … } // abstract method
Background image of page 2
Abstract – Motivating Example Graphics drawing program Define a base class Shape Derive various subclasses for specific shapes Each subclass defines its own method drawMe( ) public class Shape { public void drawMe( ) { … } // generic drawing method } public class Circle extends Shape { public void drawMe( ) { … } // draws a Circle } public class Rectangle extends Shape { public void drawMe( ) { … } // draws a Rectangle }
Background image of page 3

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

View Full DocumentRight Arrow Icon
Motivating Example – Shapes Implementation Picture consists of array shapes of type Shape [ ] To draw the picture, invoke drawMe( ) for all shapes Shape [ ] shapes = new Shape
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

04AbstractClasses - CMSC 132: Object-Oriented Programming...

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

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