What you need to learn here are:
1. Inheritance
2. Polymorphism
And then later on, in the advanced concepts, you also need to understand how an API is developed. Probably, in most cases, an interface is used where you need to define a structure of your contract — in APIs, especially where you are using interfaces etc, you define contracts, instead of simple objects. The reason is, an interface must be implemented. That interface, can be used to ensure that the client applications, using our API, has written an implementation of our standard — structure etc.
Interfaces are not only used in Java, they are also used in C# and C++ (although, C++ does not provide any keyword interface). The logical usage of them is applied when you are developing a client application, I would not use (nor recommend) considering them in a plain application.
Need an example? Sure, read the tutorial in the Oracle documents, they provide a very good example of a Bicycle API,
interface Bicycle {
void changeCadence(int newValue);
void changeGear(int newValue);
void speedUp(int increment);
void applyBrakes(int decrement);
}
Now, if you want to create an implementation of this standard, then you implement all the interface itself,
class ACMEBicycle implements 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);
}
}
Notice the empty method bodies in the interface, and the addition of bodies to the same functions in the class. There is one more extra thing in the class,
can you guess that?
I would leave the rest up to you, please also open up NetBeans and try to mess around here and there with a few things to understand how they work.