急急急!在线等JAVA高手,帮忙解答下几面2道题,我们马上交作业了,不会做,万分感激

1、指出下列Java程序中的错误,并修改使之能够正确运行

abstract class Student{

abstract void isPass( ) { };

}

class UnderGraduate extends Student {

public void isPass( ) {System.out.println("Pass!");}

}

public class AbstarctTest{

public static void main(String args[]) {

Student s;

s=new Student();

}

2.请在下面Java程序的划线处填上适当语句,使程序能够正常运行

public class MyClass {

public static void main(String args[]) {

try{ myMethod( );

}catch(MyException e) {

System.out.println(e.getMessage( ));

}

}

public----------------void MyMethod(
) ---------------- { //方法中声明抛弃用户自定义异常

throw ---------------- ;

}

}

class MyException extends---------------- { //用户自定义异常类

public String toString( ){

return "用户自定义异常";

}

}

考试过后自己要去调试一下

1.
################################
abstract class Student{

  abstract void isPass( ) { };

}

class UnderGraduate extends Student {

  public void isPass( ) {System.out.println("Pass!");}

}

public class AbstarctTest{

  public static void main(String args[]) {

   Student s;

   //s=new Student();
   s = new UnderGraduate();

}
2.
################################
public class MyClass {

  public static void main(String args[]) {

      try{  myMethod( );

      }catch(MyException e) {

         System.out.println(e.getMessage( ));

      }

  }

  public static void MyMethod() throws MyException { //方法中声明抛弃用户自定义异常

      throw new MyException()   ; 

  }   

}

class MyException extends Exception {    //用户自定义异常类

  public String toString( ){  

     return "用户自定义异常";

  }

}

温馨提示:内容为网友见解,仅供参考
第1个回答  2013-06-09

    s=new Student();
    改成

    s=new UnderGraduate();

    static

    MyException

    new  MyException();

    Exception

     

第2个回答  2013-06-09
public class AbstarctTest {
public static void main(String args[]) {
Student s = new UnderGraduate();
}
}

public abstract class Student {
abstract void isPass();
}

public class UnderGraduate extends Student {
public void isPass( ) {
System.out.println("Pass!");
}
}

public class MyException extends RuntimeException {

private String msg;

public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public MyException() {
super();
}

public MyException(String message) {
super(message);
this.msg = message;
}
}

public class MyClass {
public static void main(String args[]) {
try{
myMethod();
}catch(MyException e){
System.out.println(e.getMessage() +" ===");
}
}
public static void myMethod(){
if(true){
throw new MyException("this is test");
}
}
}
第3个回答  2013-06-09
public abstract class Student {
abstract void isPass();
}
s=new Student();改成
s=new UnderGraduate();

static throws MyException MyException Exception
第4个回答  2013-06-09
abstract void isPass( ) { }; 去掉{}变成抽象方法
s=new Student(); 不能直接new 抽象类实例,new UnderGraduate()
第5个回答  2013-06-09
第一题:原因,抽象方法后面不能有方法体,并且抽象类不能new对象,public static void main(String args[]) { UnderGraduate u=new UnderGraduate (); u.isPass();}

第二题 throw new RuntimeException;
相似回答