Abstraction & Polymorphism
Abstraction & Polymorphism
with Java
(CT038-3-2)
Prepared by: Lee Kim Keong First Prepared on: June 13 Last Modified on: April 19
Quality checked by: null
Copyright 2019 Asia Pacific University of Innovation and Technology
Topic & Structure of the lesson
• Polymorphism
• Abstract Classes & Methods
• Example
• Interfaces
• Example
• Interfaces vs. Abstract Classes
// constructor
public Point(int xValue, int yValue) {
// implicit call to Object constructor occurs here
x = xValue; // no need for validation
y = yValue; // no need for validation
}
// constructor
public Circle(int x, int y, double radiusValue) {
super( x, y ); // call Point constructor
setRadius( radiusValue );
}
// set radius
public void setRadius(double radiusValue) {
radius = (radiusValue < 0.0 ? 0.0 : radiusValue);
}
System.exit( 0 );
} // end main