Topic: 一个小程序,大家看看它哪错了?谢谢了!

  Print this page

1.一个小程序,大家看看它哪错了?谢谢了! Copy to clipboard
Posted by: jakiey
Posted on: 2005-03-29 17:39

class Plate {
  Plate (int i){
    System.out.println("Plate constructor");
  }
}

class Dinnerplate extends Plate {
  Dinnerplate(int i){
    super(i);
    System.out.println("Dinnerplate constructor");
  }
}

class Utensil{
  Utensil(int i){
    System.out.println("Utensil constructor");
  }
}

class Spoon extends Utensil{
  Spoon (int i){
    super(i);
    System.out.println("Spoon constructor");
  }
}

class Fork extends Utensil{
  Fork (int i){
    super (i);
    System.out.println("Fork constructor");
  }
}
class Custom{
  Custom(int i){
    System.out.println("Custom constructor");
  }
}
public class A extends Custom{
  
private Spoon sp;
private Fork frk;
private Dinnerplate pl;
public A (int i){
  super(i+1);
  sp=new Spoon(i);
  frk=new Fork(i);
  pl=new Dinnerplate(i);
  System.out.println("A constructor");
}
  public static void main(String[] args) {
    
    A x=new A(1);
    
  }  
}

2.Re:一个小程序,大家看看它哪错了?谢谢了! [Re: jakiey] Copy to clipboard
Posted by: why
Posted on: 2005-03-29 18:20

It looks okay, what's wrong?

3.我看可以运行啊(运行环境:j2sdk1.4.2_05) [Re: jakiey] Copy to clipboard
Posted by: fenglinlly
Posted on: 2005-03-29 22:03

这个程序没错
结果如下:
C:\Documents and Settings\Xiaoming_Feng>cd C:\j2sdk1.4.2_05\bin

C:\j2sdk1.4.2_05\bin>javac A.java

C:\j2sdk1.4.2_05\bin>java A
Custom constructor
Utensil constructor
Spoon constructor
Utensil constructor
Fork constructor
Plate constructor
Dinnerplate constructor
A constructor

C:\j2sdk1.4.2_05\bin>

4.Re:一个小程序,大家看看它哪错了?谢谢了! [Re: jakiey] Copy to clipboard
Posted by: jakiey
Posted on: 2005-03-30 08:09

不好意思!这个程序本身没有错误,可能我用jcreator编译的时候设置有问题。
现在好了。


   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