所以我是Java新手,我嘗試使用try,catch和finally特性。由於我的理解有限,try-catch塊允許我處理異常,而不是編譯器拋出一個我無法返回執行的錯誤。這是正確的嗎?另外,我的程序似乎沒有工作,因爲編譯器會拋出「Extracur是抽象的,無法實例化!」編譯期間。我怎樣才能讓它顯示我的錯誤信息(並執行我的finally塊)呢?嘗試在JAVA中處理InstantiationException,編譯器會拋出它而不是
try {
extracur student1 = new extracur();
} catch (InstantiationException e) {
System.out.println("\n Did you just try to create an object for an interface? Tsk tsk.");
} finally {
ReportCard student = new ReportCard("Progress Report for the year 2012-13");
student.printReportCard();
}
PS-extracur是一個接口。
try/catch塊是一類在那裏捕獲運行時異常 - 運行一個程序,你需要編譯它 - 編譯錯誤需要修復程序編譯... – assylias
啊。這就說得通了!非常感謝! –