1/14
From Dr. Pittman's Lecture Slides
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No study sessions yet.
Inheritance
The idea that the child class inherits both data and behaviors from the parent class
Benefit of Inheritance
Allows us to make more generic classes from which more specific classes can inherit variables and methods.
Key Word for Inheritance
Extends -
public class Programmer extends Employee{}
Object Class
Automatically extended for every class
Object Class Public Methods
getClass()
hashCode()
toString()
equals()
Premade classes that inherit Object Class
String
ArrayList
Double
toString()
returns a String that represents the object
equals()
compares two objects by checking if their reference values are equivalent (same as ‘==’)
Superclass
Parent Class
Subclass
Child Class
super
super(name, address, phoneNumber, idNumber);
used to reference methods of the parent class
Use of Getters/Setters
If the Super class has any private variables or methods, the subclass will need the getters and setters to modify the private variables
Overriding
@Override
public String toString(){
this allows the method that was inherited to be rewritten to handle the specific need of the subclass while still using the same name and parameter
Overriding
A subclass provides a new implementation for a method defined in tis superclass
Overloading
Multiple methods in the same class share the same name but have different parameters