java中什么是Interface接口

1.Interface接口的定義和用法
先直接上大白話:馬克-to-win:接口就是灰?;页3橄蟮某橄箢?,我們可以就像用抽象類一樣用接口,只不過,interface抽象到不能再抽象了,以至于里面不能有任何方法的實現(xiàn), 只能都是空方法。緊接著來個例子:
馬克- to-win:馬克 java社區(qū):防盜版實名手機尾號: 73203。



例1.1---本章源碼

interface OpenClose {
    void open();
    void close();
}
class Shop_mark_to_win implements OpenClose {
    public void open() {
        System.out.println("商店開門了---shop open");
    }
    public void close() {
        System.out.println("商店關門了---shop close");
    }
}
class Bottle_mark_to_win implements OpenClose {
    public void open() {
        System.out.println("打開瓶子,Open the Bottle");
    }
    public void close() {
        System.out.println("蓋上瓶子Close the Bottle");
    }
}
public class Test {
    public static void main(String args[]) {
        OpenClose s = new Shop_mark_to_win();
        s.open();
        s.close();

        OpenClose b = new Bottle_mark_to_win();
        b.open();
        b.close();

        System.out.println("-----------------");
        OpenClose[] x = { s, b };
        for (int i = 0; i < x.length; i++) {
            x[i].open();
            x[i].close();
        }
    }
}




結果是:
商店開門了---shop open
商店關門了---shop close
打開瓶子,Open the Bottle
蓋上瓶子Close the Bottle
-----------------
商店開門了---shop open
商店關門了---shop close
打開瓶子,Open the Bottle
蓋上瓶子Close the Bottle