I'm currently learning more on Java, and have come across an example in a book which I think has made me misunderstand the use of Interfaces. As I see it, the interface in question is completely unnecessary, and I'd like to know if I'm reading it wrong or I should look elsewhere for a better understanding (which I have tried but don't really understand).
The Interface:
public interface Series{
int getNext();
void reset();
void setStart(int x);
}
The implementing class:
class ByTwos implements Series {
int start;
int val;
By Twos() {
start = 0;
val = 0;
}
public int getNext(){
val += 2;
return val;
}
public void reset(){
val = start;
}
public void setStart(int x){
start = x;
val = x;
}
}
I don't see what use the interface has here, why the class cannot simply remove the implements statement, and what purpose the interface really serves.
Edit: not identical to duplicate questions since I'm asking about this particular example, and those question answers aren't helping me understand the concept really.