interface A
{
public void show();
}
interface Z
{
public int add(int a,int b);
}
class Test implements A,Z//多实现
{
public int add(int a,int b)
{
return a+b+3;
}
}class InterfaceDemo1
{
public static void main(String[] args)
{ Test t = new Test();
t.add();
}
}
编译出错:
---------- Java ----------
E:\java\day9\InterfaceDemo1.java:10: Test 不是抽象的,并且未覆盖 A 中的抽象方法 show()
class Test implements A,Z//多实现
^
E:\java\day9\InterfaceDemo1.java:24: 无法将 Test 中的 add(int,int) 应用于 ()
t.add();
^
2 错误输出完成 (耗时: 1 秒)
{
public void show();
}
interface Z
{
public int add(int a,int b);
}
class Test implements A,Z//多实现
{
public int add(int a,int b)
{
return a+b+3;
}
}class InterfaceDemo1
{
public static void main(String[] args)
{ Test t = new Test();
t.add();
}
}
编译出错:
---------- Java ----------
E:\java\day9\InterfaceDemo1.java:10: Test 不是抽象的,并且未覆盖 A 中的抽象方法 show()
class Test implements A,Z//多实现
^
E:\java\day9\InterfaceDemo1.java:24: 无法将 Test 中的 add(int,int) 应用于 ()
t.add();
^
2 错误输出完成 (耗时: 1 秒)
2. 在接口InterfaceDemo1中,接口是不能实例化的。
2、你根本就没有add()这个方法,参数不对
修改如下:
package com.test;
interface A{
public void show();
}interface Z {
public int add(int a, int b);
}class Test implements A, Z// 多实现
{
@Override
public void show() {
// TODO Auto-generated method stub
System.out.println("接口定义的每个方法必须实现");
} public int add(int a, int b) {
System.out.println("test");
return a + b + 3;
}
}public class InterfaceDemo1 {
public static void main(String[] args) { Test t = new Test();
t.add(1,2); }
}
---------- Java L ----------
test
test
10输出完成 (耗时: 0 秒)