10slide_2007 - Chapter 10 Abstract Classes and Interfaces...

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

View Full Document Right Arrow Icon
EE3206/EE5805 Java Programming & Applications EE3206/EE5805 Java Programming & Applications 1 Chapter 10 Chapter 10 Abstract Classes and Interfaces Abstract Classes and Interfaces
Background image of page 1

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

View Full DocumentRight Arrow Icon
EE3206/EE5805 Java Programming & Applications EE3206/EE5805 Java Programming & Applications 2 Objectives Objectives To design and use abstract classes. To declare interfaces to model weak inheritance relationships. To define a natural order using the Comparable interface. To know the similarities and differences between an abstract class and an interface. To declare custom interfaces. To enable objects cloneable using the Cloneable interface. To create a generic sort method.
Background image of page 2
EE3206/EE5805 Java Programming & Applications EE3206/EE5805 Java Programming & Applications 3 What is Abstract Type? What is Abstract Type? • Abstract types are useful in that they can be used to define and enforce a protocol ; a set of operations which all objects that implement the protocol must support. • The fact that Java language disallow instantiation of abstract types and force subtypes to implement all needed functionality further ensures program correctness. • This class is used as a base class for defining a new subclass.
Background image of page 3

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

View Full DocumentRight Arrow Icon
EE3206/EE5805 Java Programming & Applications EE3206/EE5805 Java Programming & Applications 4 The The abstract abstract Modifier Modifier The keyword abstract can be applied to a class or a method: The abstract class Cannot be instantiated Should be extended and implemented in subclasses The abstract method Method signature without implementation public abstract double getArea();
Background image of page 4
EE3206/EE5805 Java Programming & Applications EE3206/EE5805 Java Programming & Applications 5 Example Without Using Abstract Classes Example Without Using Abstract Classes GeometricObject -color: String -filled: boolean -dateCreated: java.util.Date +GeometricObject() +getColor(): String +setColor(color: String): void +isFilled(): boolean +setFilled(filled: boolean): void +getDateCreated(): java.util.Date +toString(): String The color of the object (default: white). Indicates whether the object is filled with a color (default: false). The date when the object was created. Creates a GeometricObject. Returns the color. Sets a new color. Returns the filled property. Sets a new filled property. Returns the dateCreated. Returns a string representation of this object. Circle -radius: double +Circle() +Circle(radius: double) +getRadius(): double +setRadius(radius: double): void +getArea(): double +getPerimeter(): double +getDiameter(): double Rectangle -width: double -height: double +Rectangle() +Rectangle(width: double, height: double) +getWidth(): double +setWidth(width: double): void +getHeight(): double +setHeight(height: double): void +getArea(): double +getPerimeter(): double From Chapter 9
Background image of page 5

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

View Full DocumentRight Arrow Icon
EE3206/EE5805 Java Programming & Applications EE3206/EE5805 Java Programming & Applications 6 Using Abstract Classes Using Abstract Classes GeometricObject Circle Rectangle GeometricObject -color: String -filled: boolean -dateCreated: java.util.Date #GeometricObject() +getColor(): String +setColor(color: String): void +isFilled(): boolean +setFilled(filled: boolean): void +getDateCreated(): java.util.Date
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 31

10slide_2007 - Chapter 10 Abstract Classes and Interfaces...

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

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