日期:2014-05-20  浏览次数:20839 次

难道这个是多态?
[code=Java][/code]interface Inter  
{  
  void method();  
}  
class Test  
{  
  static class Demo implements Inter  
  {  
  public void method()  
  {  
  System.out.println("哈哈哈哈");  
  }  
  }  
  static Inter function()  
  {  
  return new Demo();  
  }  
}  
class Demodemo7  
{  
  public static void main(String[] args)  
  {  
  Test.function().method();  
  }  
}  


---------------------------------------------------
 static Inter function()  
 {  
  return new Demo();  
 }  

我想问下 为什么Inter 作为返回值也能编译通过? Demo不是只是实现了Inter 又没有继承Inter


------解决方案--------------------
这种用法很多见 啊,面向接口编程嘛,比如说
List getList(){
return new ArrayList();
}
实现也是继承的一种啊