So I was given this code in a folder of bits and pieces that were to be for a project which has since halted development. However, being new to Java there are several questions I have (and I'm aware the code does not compile, but that works into one of my questions).
interface Executable {
public int execute (Object o);
}
public class Biv implements Executable {
public int execute (String s) {
System.out.println (s);
return s.length();
}
public static void main (String[] args) {
Executable e = new Biv();
System.out.println(
e.execute ("Hello World!"));
}
}
1) My first question is to do with the variable e. It is declared with the Executable object type, however I don't understand why it can then be instantiated with a new Biv object. What is going on here, what does it mean?
2) The error is in the execute method within the Biv class. This seems to be because it expects an object rather than a String. However, can you not replace a Object with a String because String is a subclass of Object? I could understand if you replaced String with Object it would have an error (I think) but not how it is currently done.