Topic: 高手指点一下接口

  Print this page

1.高手指点一下接口 Copy to clipboard
Posted by: missyou
Posted on: 2004-10-01 22:24

看书不明白,这个那里些错了啊。我模仿书上写的。但是不能编译

interface ccc()
{
void c(int p);
{
}
}

class sss implements ccc
{
public void c(int p)
{
System.out.println(p*p);
}
}

class fff
{
public static void main(String args[])
{
ccc s = new ccc();
sss a = new sss();
s.c(5);

s = a;
s.c(5);
}
}

2.Re:高手指点一下接口 [Re: missyou] Copy to clipboard
Posted by: zerol
Posted on: 2004-10-01 23:21

interface ccc() <----- () should be deleted.

3.Re:高手指点一下接口 [Re: missyou] Copy to clipboard
Posted by: missyou
Posted on: 2004-10-01 23:54

这是。。

4.Re:高手指点一下接口 [Re: missyou] Copy to clipboard
Posted by: zerol
Posted on: 2004-10-01 23:57

ccc 是接口, 不能被实例化。

ccc s = new ccc(); 可能应该是 ccc s = new sss(); 吧

5.Re:高手指点一下接口 [Re: missyou] Copy to clipboard
Posted by: missyou
Posted on: 2004-10-02 00:05

这是。。

6.Re:高手指点一下接口 [Re: missyou] Copy to clipboard
Posted by: zerol
Posted on: 2004-10-02 00:09

同一个错误。

7.Re:高手指点一下接口 [Re: missyou] Copy to clipboard
Posted by: missyou
Posted on: 2004-10-02 09:11

谢谢啊

可是书上是这样写的,结果不一样的
class fff
{
  public static void main(String args[])
  {
    ccc s = new ccc();
    sss a = new sss();
    s.c(5);
    
    s = a;
    s.c(5);
  }
}

8.Re:高手指点一下接口 [Re: missyou] Copy to clipboard
Posted by: steven_652
Posted on: 2004-10-08 19:57

应该是ccc s = new sss();
接口不能被实例化的

9.Re:高手指点一下接口 [Re: missyou] Copy to clipboard
Posted by: arthas1982
Posted on: 2004-10-09 09:02

接口可以声明一个符合接口方法的类,但是不能定义这个类。

10.Re:高手指点一下接口 [Re: missyou] Copy to clipboard
Posted by: jameszhang
Posted on: 2004-10-09 09:36

如果书上真这么写,可以把它扔了,省得害自己,呵呵

11.Re:高手指点一下接口 [Re: missyou] Copy to clipboard
Posted by: robin519
Posted on: 2004-11-07 15:40

ccc s = new ccc();错误,应该用implements实例化,不能用new()方法
s = a; 这句也不对

12.Re:高手指点一下接口 [Re: missyou] Copy to clipboard
Posted by: woaizpgf
Posted on: 2004-11-07 21:37

尽信书、不如无书


   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