Saturday, August 21, 2010

Interfaces: TestIface.java

Courtesy of Sun Web Learning Center

 3. interface MyInterface {
 4.   static long boat = 7L;
 5.   long myMethod(long x);
 6. }
 7. public class TestIface implements MyInterface {
 8.   public static void main(String[] args) {
 9.     new TestIface().myMethod(6L);
10.   }
11.   long myMethod(long x) {
12.     System.out.println( ((++x * boat) - (--x + 1)) );
13.     return 42L;
14.   }
15. }

What is the result?


A     40
B     41
C     42
D     43
E     Compilation fails.
F     An exception is thrown at runtime.

No comments:

Post a Comment