您的位置 首页 java

java中什么是Interface接口

1.Interface接口的定义和用法
先直接上大白话:马克-to-win:接口就是灰常灰常抽象的抽象类,我们可以就像用抽象类一样用接口,只不过,interface抽象到不能再抽象了,以至于里面不能有任何方法的实现, 只能都是空方法。紧接着来个例子:
马克- to-win:马克 java社区:防盗版实名手机尾号: 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();
}
}
}

篇幅有限更多请见扩展链接:

文章来源:智云一二三科技

文章标题:java中什么是Interface接口

文章地址:https://www.zhihuclub.com/185602.shtml

关于作者: 智云科技

热门文章

网站地图