Topic: 接口,这东西到底怎么用?

  Print this page

1.接口,这东西到底怎么用? Copy to clipboard
Posted by: chorgrobb
Posted on: 2005-04-06 22:23

我是新手,希望各位高手指点一二。谢谢!!

2.Re:接口,这东西到底怎么用? [Re: chorgrobb] Copy to clipboard
Posted by: ginger547
Posted on: 2005-04-08 15:06

这东西说起来可就难了 建议你去查一下资料
简单一句话 interface是建立东西不实现 等你用的时候 具体实现它

明白了吗 就是放个空架子在那

等你往里塞东西 不知道这样说明白不明白
//MyInterface.java
interface MyInterface{
int add(int i);
int sub(int j);
}
//TestInterface.java
public TestInterface{
int k=0;
int add(int i){
k+=i;
return k;
}
int sub(int j){
k-=j;
return k;
}
public static void main(String[] args){
TestInterface ti = new TestInterface();
ti.add();
ti.sub();
}
}

3.Re:接口,这东西到底怎么用? [Re: chorgrobb] Copy to clipboard
Posted by: 雪中行
Posted on: 2005-04-09 15:17

同意上面的回答!

4.Re:接口,这东西到底怎么用? [Re: chorgrobb] Copy to clipboard
Posted by: 蘑蘑茶
Posted on: 2005-04-10 09:07

我老师说一般很少用是真的吗/?

5.Re:接口,这东西到底怎么用? [Re: 蘑蘑茶] Copy to clipboard
Posted by: littledeer1974
Posted on: 2005-04-10 09:54

我觉得你的老师说的不对
接口,用的还是很多的
有些地方,甚至还没有接口不行

6.Re:接口,这东西到底怎么用? [Re: chorgrobb] Copy to clipboard
Posted by: fenglinlly
Posted on: 2005-04-10 11:05

明白了吗 就是放个空架子在那

等你往里塞东西 不知道这样说明白不明白
//MyInterface.java
interface MyInterface{
int add(int i);
int sub(int j);
}
//TestInterface.java
public class TestInterface implements MyInterface{
int k=0;
int add(int i){
k+=i;
return k;
}
int sub(int j){
k-=j;
return k;
}
public static void main(String[] args){
TestInterface ti = new TestInterface();
ti.add();
ti.sub();
}
}

7.Re:接口,这东西到底怎么用? [Re: chorgrobb] Copy to clipboard
Posted by: lcwling
Posted on: 2005-04-10 13:49

或许,你比较一下abstract class和interface,更助于你理解
http://www.cjsdn.net/post/view?bid=53&id=69871&sty=2

(BTW,老话重提,提问前记得search,学会自己找答案!)

8.Re:接口,这东西到底怎么用? [Re: chorgrobb] Copy to clipboard
Posted by: chorgrobb2008
Posted on: 2005-04-11 00:53

谢谢各位

9.Re:接口,这东西到底怎么用? [Re: littledeer1974] Copy to clipboard
Posted by: 蘑蘑茶
Posted on: 2005-04-11 09:27

littledeer1974 wrote:
我觉得你的老师说的不对
接口,用的还是很多的
有些地方,甚至还没有接口不行

它和抽象类有什么区别呢???

10.Re:接口,这东西到底怎么用? [Re: 蘑蘑茶] Copy to clipboard
Posted by: littledeer1974
Posted on: 2005-04-11 10:50

蘑蘑茶 wrote:
它和抽象类有什么区别呢???


you can


class yourClass implements interface_a,interface_b,interface_c,...{
//your class contents
}


you can not


class yourClass extends abstractclass_a,abstractclass_b,...{
//your class contents
}


althougu it is only one difference between them
the other guy will tell you more.....Smile

11.Re:接口,这东西到底怎么用? [Re: chorgrobb] Copy to clipboard
Posted by: rumly
Posted on: 2005-04-13 12:04

关键在于是否能实现多继承

12.Re:接口,这东西到底怎么用? [Re: chorgrobb] Copy to clipboard
Posted by: jerryjerry123
Posted on: 2005-04-13 13:24

接口在Swing编程的事件处理中广泛应用


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923