public interface Cabin
{
 public void setName( String str ) throws Exception;
 public String getName()..
 public void SetDuck( int n )..
 public int getDuck()...
}
class CabinBean implements Cabin
{
 private String name;
 private int duck;
 ...
 ...实现Cabin接口的方法
}
public class CabinTest
{
 Cabin cabin = new CabinBean();
 //这里可以调用Cabin接口中的方法
}...越来越觉得接口好用 接口是java的精髓之一  尤其在EJB 和设计模式中用得相当普遍

解决方案 »

  1.   

    public interface testInterface {
    String getName();
    }
    public class testClass implements testInterface {
     public String getName() {
    return "testClass";
     }
    }public class test 
    {
     
     public void printName(testInterface t)
     {
        System.out.println(t.getName());
      } public static void main(String[] args) {
     
          testClass _testClass = new testClass();
          test _test = new test();
          _test.printName(_testClass);
     }
    }
      

  2.   

    谢谢!节贴了!
    我要再发一个,java接口功能讨论的帖子,希望能听到各位的高见!