(4) Abstract Classes

(4) Abstract Classes - Reading CMSC 132: Object-Oriented...

Info iconThis preview shows pages 1–3. 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 1 Reading Read Section 3.3 in the Koffman text (Section 1.4 in the second edition) 2 The modifer abstract Description: Represents generic concept It's just a placeholder It means that the lower-level implementation details are being left to subclasses Can be applied to methods and classes Examples: abstract class MyClass { } // abstract class abstract void myMethod() { } // abstract method 3 abstract – motivating example A graphics drawing program Defines 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 } 4
Background image of page 1

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

View Full DocumentRight Arrow Icon
Shapes example, con't. Implementation:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

(4) Abstract Classes - Reading CMSC 132: Object-Oriented...

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

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