JAVA期末复习资料2(5)

2019-08-30 18:09

{

callMethod(); }

catch(Exception e) {

System.out.print(\ }

System.out.println(\ }

static void createException() {

throw new ArithmeticException(); }

static void callMethod() {

try {

createException();

System.out.print(\ }

catch(ArrayIndexOutOfBoundsException e) {

System.out.print(\ }

finally {

System.out.print(\ }

System.out.print(\ } }

8、仔细阅读下面的程序代码,若经编译和运行后,请写出打印结果。 class myException extends Exception{} public class Sample{ public void foo(){ try{

System.out.print(1); bar();

System.out.print(2); }catch(myException e){ System.out.print(3); } finally{

System.out.print(4); } }

public void bar() throws myException{ throw new myException(); }

public static void main(String args[]){ Sample s=new Sample(); s.foo(); } }

9、仔细阅读下面的程序,写出程序的执行顺序(写出编号): public class UsingExceptions {

public static void main( String args[] ){ try{

method1(); // 1 }catch(Exception e){

System.err.println(e.getMessage()); // 2 }

finally{

System.out.println(\ } }

public static void method1() throws Exception { method2(); //4 }

public static void method2() throws Exception { method3(); //5 }

public static void method3() throws Exception{

throw new Exception( \ } }

10、阅读下面的程序Test.java: import java.io.*; public class Test{

public static void main(String argv[]){ Test t = new Test();

System.out.println(t.fliton()); }

public int fliton(){ try{

FileInputStream din = new FileInputStream(\

din.read();

}catch(IOException ioe){

System.out.println(\ return -1; }

finally{

System.out.println(\ }

return 0; } }

如果文件test.txt与Test.java在同一个目录下,test.txt中仅有一行字符串“hello world!”,上面的程序编译是否成功?如果编译出错,指出哪行出错,并说明理由;如果编译正确,运行结果是什么?

11、阅读下面的程序,写出带划线语句或注释,并写出该程序的作用: import java.io.*; public class Test {

public static void main(String args[]) { scanFiles(\ }

public static void scanFiles(String path) { if (path == null) return;

File f = new File(path); // if (!f.exists()) return;

if (f.isFile()) // System.out.println(f.getAbsolutePath()); else {

File dir[] = f.listFiles(); for (int i = 0; i < dir.length; i++)

scanFiles(dir[i].getAbsolutePath());// } } }


JAVA期末复习资料2(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:关于调整康平县工业用地基准地价出让金租金标准的通知-30%

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: