Given:
interface Shape { int patent = 12345; Shape doShape();//w w w . j ava 2s . com } public class Main implements Shape { int patent = 34567; public static void main(String[] args) { new Main().doShape(); } Main doShape() { System.out.println(++patent); return new Main(); } }
If javac is invoked twice:
javac -source 1.4 Main.java javac Main.java
And, if "java Main" is invoked whenever Main compiles, what is the result?
F is correct.
Regardless of the Java version, the implementing doShape()
method must be declared public.
If it was declared public, the answer would be B.
The Java 1.4 compilation would fail because doShape()
is using a covariant return, which wasn't available until Java 5.