急用!!!关于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,求帮忙!急!!!
[解决办法]
这段代码编译不了。
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); } }}
[解决办法]
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); }}