default method in interfaces in java
我试图使用以下代码了解Java中接口的默认方法,但我无法编译它:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
编译器生成以下输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | c.java:2: error: illegal start of type default void foo(){ ^ c.java:2: error: = expected default void foo(){ ^ c.java:2: error: ';' expected default void foo(){ ^ c.java:2: error: illegal start of type default void foo(){ ^ c.java:2: error: expected default void foo(){ ^ c.java:2: error: = expected default void foo(){ ^ c.java:2: error: ';' expected default void foo(){ ^ c.java:3: error: illegal start of type System.out.println("Calling A.foo()"); ^ c.java:3: error: = expected System.out.println("Calling A.foo()"); ^ c.java:3: error: expected System.out.println("Calling A.foo()"); ^ c.java:3: error: illegal start of type System.out.println("Calling A.foo()"); ^ c.java:5: error: class, interface, or enum expected } |
我无法理解这些错误。 如何更正代码中的问题?