What is a Class?
A class is a blueprint (a design plan)
- Fields (Instance Variables)
- Constructors
- Methods (Functions)
What is Inheritance?
- What do classes have
in common?
- Abstract out those features
- Override or extend methods that don't work.
Is A? versus Has A?
- Is A? Helps you decide if a class should extend another.
- Is A "Dog" an "Animal"?
- Is A "Dog" a "Cat"?
- Has A? Helps you decide if something is a field.
- Dog Has A height.
When to use Inheritance?
- When the subclass Is A superclass: "Dog Is An Animal"
- When a subclass need most of the methods in a superclass.
- Almost every method in Animal is used in Dog.
- Don't: Use inheritance just to reuse code, or they don't have
an Is A relationship.
Back to Inheritance?
- Fields and Methods are already defined
when you extend the super class.
- You define only the changes.
Why we use Inheritance?
- Avoid duplicate code.
- Changes to superclass code is instantly reflected in subclasses.
- User knows that all subclasses have all of the methods of the superclass.
Types of Inheritance?
What do we use
Getters and Setters?
In order to protect each object data.
Getters = Accessors || Setters = Mutators
String newName here is a "Parameter"
What is main for?
Main creates the objects and then they interact.
Grover here is an "Argument"
Instance Variables &
Local Variables
Java Basics pt1
By Charis Pctr
Java Basics pt1
- 953