WDD_lec_09 - Web Design & Development Lecture 9...

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

View Full Document Right Arrow Icon
Lecture 9
Background image of page 1

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

View Full DocumentRight Arrow Icon
Abstract Classes a and Interfaces
Background image of page 2
Abstract Classes
Background image of page 3

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

View Full DocumentRight Arrow Icon
Class Shape Hierarchy Consider the following class hierarchy Shape Circle Square
Background image of page 4
Problem AND Requirements Suppose that in order to exploit polymorphism, we specify that 2-D objects must be able to compute their area. All 2-D classes must respond to area() message. How do we ensure that? Define area method in class Shape Force the subclasses of Shape to respond area() message Java’s Solutions Abstract Classes Interfaces
Background image of page 5

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

View Full DocumentRight Arrow Icon
Abstract Classes Idea To define only part of an implementation Can contain instance variables & methods that are fully implemented Leaving the subclasses to provide the details Any class with an abstract method must be declared abstract However you can declare a class abstract that has no abstract method. An abstract method has no implementation (known in C++ as a pure virtual function)
Background image of page 6
Abstract Classes If subclass overrides all abstract methods of the superclass, than it becomes a concrete class otherwise we have to declare it as abstract or we can not compile it Any subclass can override a concrete method inherited from the superclass and declare them abstract An abstract class cannot be instantiated However references to an abstract class can be declared Can point to the objects of concrete subclasses
Background image of page 7

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

View Full DocumentRight Arrow Icon
Shape.java /* This is an example of abstract class. Note that this class contains an abstract method with no definition. */ public abstract class Shape {
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 29

WDD_lec_09 - Web Design & Development Lecture 9...

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

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