Pr2 Lec5
Pr2 Lec5
Lecture 5
Inheritance and Data Abstraction
Outline
• Data abstraction
• Inheritance
References
What is data abstraction?
{
name: “Car”,
model: “M1”,
color: “red”,
power: 450
}
Features of data abstraction
• What is inheritance?
• Why do we need inheritance?
• Pull out the common properties into a new position (a new class,
called parent class or superclass).
Public class Programmer Public class Manager extends Public class Employee{
extends Employee{ Employee{ private String address;
private String[] languages; void reportProjectStatus(){} private String name;
void writeCode(){} } private String phone;}
}
Extensibility
• Implement Point2D.java,
Point3D.java
and
TestPoint2DPoint3D.java
• Inheritance
• Subclasses and Superclass
• Method Overriding
• Single Inheritance