首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

急用!关于java的解决方案

2012-02-19 
急用!!!关于java的class MyException extends Exception{private:int detailMyException(int a){ detail

急用!!!关于java的
class MyException extends Exception
{
private:
int detail;
  MyException(int a){ detail = a;}
public:
String toString(){ return "MyException"+detail; }
}
public class ExceptionDemo{
  public static void compute(int a) throws MyException {
  System.out.println("called compute("+a+")");
  if(a>10) throw new MyException(a);
  System.out.println("normal exit");  
  }  
  public static void main( String args[] ){
  try{ compute(6 ); compute( 12 ); }
  catch(MyException e){  
  System.out.println("Caught "+e);  
  }  
这个程序运行后的结果是什么啊,本人没装java,求帮忙!急!!!

[解决办法]
这段代码编译不了。

Java code
class MyException extends Exception{    private int detail;    public MyException(int a){        detail = a;    }    @Override public String toString(){        return "MyException" + detail;    }}public class ExceptionDemo{    public static void compute(int a) throws MyException {        System.out.println("called compute("+a+")");        if(a>10)            throw new MyException(a);        System.out.println("normal exit");    }    public static void main( String args[] ){        try {            compute(6 );            compute( 12 );        }        catch(MyException e){            System.out.println("Caught "+e);        }    }}
[解决办法]
Java code
public class Test extends TT {    public static void main(String args[]){        Test t = new Test("Tom");    }    public Test(String s){        super(s);        System.out.println("How do you do?");    }    public Test(){        this("I am Tom");    }}class TT{    public TT(){        System.out.println("What a pleasure!");    }    public TT(String s){        this();        System.out.println("I am "+s);    }} 

热点排行