I have a class called Node and another class called ClassicNode which extends Node. Now I have an interface AgentInterface implemented by ClassicNode class. The interface states that there must be a method
Node selection();
As you can see, the return type should be of type Node. But in the class ClassicNode can I implement it like this instead:-
ClassicNode selection(){
//Code
}
Will this satisfy the interface? (since ClassicNode inherits Node)
Yes; it’s called covariant return. Note, though, that you cannot do the same thing with parameters; they must match exactly.