当前位置: 代码迷 >> J2SE >> java抽象方法的定义解决办法
  详细解决方案

java抽象方法的定义解决办法

热度:202   发布时间:2016-04-24 02:23:36.0
java抽象方法的定义
interface A{
public String str="sunxiaolong";
public void print();
public String getinfo();
}
interface B{
public void say(){
System.out.println("hello world");为什么不能在此添加系统输出语句。
  }
  
}
class X implements A,B{
  public void say(){
System.out.println("hello world");
  }
  public void print(){
System.out.println("zuozhe="+str); 
  }
  public String getinfo(){
return "info";
  }
}
public class Demo{
public static void main(String []args){
X d=new X();
d.say();
d.print();
}
}







------解决方案--------------------
Java code
interface B{public void say(){System.out.println("hello world");为什么不能在此添加系统输出语句。  }   }
------解决方案--------------------
记住 接口定义的方法不能写任何实现代码
------解决方案--------------------
接口中不能写方法的具体实现,只能写方法的返回类型,参数列表。
------解决方案--------------------
Java code
//接口该这么写,里面不能写具体实现.交给实现这个接口的类来写interface B{public void say();}class X implements B{  public void say(){System.out.println("hello world");  }}
  相关解决方案