Is it possible to access to field or function of a class object that implements an interface using interface object?
for example:
public interface Node { // reference to all my trucks
void collect(Package p);
void deliver(Package p);
void work();
}
public class Truck implements Node{...}
public class Van extends Truck {...}
public class Tracking {
private Node node;
@Override
public String toString() {
return "time:" + time + " " + node + ", status=" + status;
}
}
And from another class I try to print Tracking and get node to be specific function from Van class but instead the node return only the toString of the van function. And I have no access to other functions.
for (int i = 0; i < this.tracking.size(); i++) {
System.out.println(this.tracking.get(i));
}
The main problem to access to the truckID field
I would appreciate an explanation on how to solve this.

printlnthe defaulttoStringis called, but you can try to explicitly call another method yes