OOP Interfaces and Inheritance.
What Is an Object?
It’s an instance of the class.
Benefits of Bundling code into individual software objects:
- Modularity: The source code for an object can be written and maintained independently of the source code for other objects.
- Information-hiding.
- Code re-use.
- Pluggability and debugging.
What Is a Class?
A class is a blueprint for object are created.
Example
class Bicycle {
int cadence = 0;
int speed = 0;
int gear = 1;
void changeCadence(int newValue) {
cadence = newValue;
}
void changeGear(int newValue) {
gear = newValue;
}
void speedUp(int increment) {
speed = speed + increment;
}
void applyBrakes(int decrement) {
speed = speed - decrement;
}
void printStates() {
System.out.println("cadence:" +
cadence + " speed:" +
speed + " gear:" + gear);
}
}
What Is Inheritance?
Inheritance is to allow object acquires all the properties and behaviors of a parent object
Example
class MountainBike extends Bicycle {
// new fields and methods defining
// a mountain bike would go here
}
What Is an Interface?
An interface is a contract between a class and the outside world.
Example

Useing Interface VS. Inheritance.

What Is a Package?
A package is a namespace for organizing classes and interfaces in a logical manner.