//定义接口InterfaceA  
interface InterfaceA  
{  
 void fun();  
}  
//实现接口InterfaceA的类Bimpl  
class Bimpl implements InterfaceA  
{  
 public void fun()  
 {  
  System.out.println(“This is B”);  
 }  
}  
  
//实现接口InterfaceA的类Cimpl  
class Cimpl implements InterfaceA  
{  
 public void fun()  
 {  
  System.out.println(“This is C”);  
 }  
}  
  
class Test  
{  
 public static void main(String[] args)  
 {  
  InterfaceA a;  
  a= new Bimpl();  
  a.fun();  
  a = new Cimpl();  
  a.fun();  
 }  
}  
    //输出结果为:
    //   This is B
    //   This is C
例子

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2022-01-18
  • 2021-11-25
  • 2022-12-23
猜你喜欢
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2021-04-03
  • 2022-12-23
相关资源
相似解决方案