slide2.2_2009_r1 - EE3206/EE5805 Java Programming and...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: EE3206/EE5805 Java Programming and Applications EE3206/EE5805 Java Programming and Applications 1 Module 2.2 Module 2.2 Inheritance and Polymorphism Inheritance and Polymorphism EE3206/EE5805 Java Programming and Applications EE3206/EE5805 Java Programming and Applications 2 Intended Learning Outcomes Intended Learning Outcomes s To develop a subclass from a superclass through inheritance. s To invoke the superclass ’ s constructors and methods using the super keyword. s To override methods in the subclass. s To distinguish differences between overriding and overloading. s To comprehend polymorphism, dynamic binding, and generic programming. s To describe casting and explain why explicit downcasting is necessary. s To restrict access to data and methods using the protected visibility modifier. s To declare constants, unmodifiable methods, and nonextendable classes using the final modifier. s To store, retrieve, and manipulates objects in an ArrayList . s To implement a Stack class using ArrayList. EE3206/EE5805 Java Programming and Applications EE3206/EE5805 Java Programming and Applications 3 Inheritance Inheritance s One class (A) can inherit all the fields and methods from another class (B) s Relationship between A (Child) and B (Parent) is referred to subclass and superclass s Reusability • Code a method once and used by all subclasses s Reduce Complexity • Subclass only need to implement the difference between itself and its parent EE3206/EE5805 Java Programming and Applications EE3206/EE5805 Java Programming and Applications 4 Superclasses Superclasses and Subclasses and Subclasses 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 GeometricObject Circle Rectangle TestCircleRectangle Run EE3206/EE5805 Java Programming and Applications EE3206/EE5805 Java Programming and Applications 5 Constructor of Constructor of Superclass Superclass s Unlike normal methods and properties, the constructor of a superclass is not inherited s A superclass (parent) must be first constructed before constructing its subclass (child)...
View Full Document

Page1 / 37

slide2.2_2009_r1 - EE3206/EE5805 Java Programming and...

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