Inheritance in java
Inheritance in java
JAVA
PROFESSOR(SCAT)
GUSCSE202232020
INHERITANCE
subclass: Employee
- employeeID: int
- salary: int
- startDate: Date
How is this useful?
Economy of time – When you implement Employee, you already have all
functionality of Person. No need to reimplement
Parameter passing – If you have a function that expects a Person, you
can pass an Employee, and it is still fine.
Fewer special-purpose functions for every type of Person that exists
Container classes (linked lists, binary trees, etc.) can be defined to hold a
Person, and can hold any subclass of Person
Allows limited heterogeneity in container classes
superclass: Person
- name: String
- dob: Date
subclass: Employee
- employeeID: int
- salary: int
- startDate: Date
What really happens?
Person Person
- name: String name = "John Smith"
- dob: Date dob = Jan 13, 1954
Employee
name = "Sally Halls"
is a kind of
dob = Mar 15, 1968
Employee employeeID = 37518
- employeeID: int salary = 65000
- salary: int startDate = Dec 15,
- startDate: Date 2000
Inheritance in Java
Class
The class called Object
Object
PROBLEM DEFINITION
1. Provide three classes named rectangle,
triangle, and circle such that each one of the
classes extends the class shape. Each one of
the classes contains only the method
printarea() that prints the area of the given
shape.