欢迎来到天天文库
浏览记录
ID:37169617
大小:39.00 KB
页数:3页
时间:2019-05-21
《2010下答案Java试卷答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、2010年(下)全国信息技术水平考试计算机程序设技术水平证书(JAVA语言)理论考试试卷一、理论题(每小题1分,共30分)12345678910BCACDBBCBB11121314151617181920ACDDDACDDB21222324252627282930CDBCCADDBD二、实践题(共70分)1、(20分)publicclassTest1{publicTest1(){}publicstaticvoidmain(String[]args){Test1test1=newTest1();System.out.println(test1.GetStr(7));Sy
2、stem.out.println(test1.GetStr(32));System.out.println(test1.GetStr(899));}privateStringGetStr(intintNo){if(intNo<10)return"00"+intNo;elseif(intNo<100)return"0"+intNo;elsereturn""+intNo;}}2、(25分)publicclassTest2{publicTest2(){}publicstaticvoidmain(String[]args){fruit[]fruits=newfruit[5];
3、fruits[0]=newApple();fruits[1]=newOrange();fruits[2]=newBanana();fruits[3]=newApple();fruits[4]=newOrange();for(inti=0;i<5;i++){System.out.println(fruits[i].GetName());}}}abstractclassfruit{publicabstractStringGetName();}classAppleextendsfruit{publicStringGetName(){return"Apple";}}class
4、Orangeextendsfruit{publicStringGetName(){return"Orange";}}classBananaextendsfruit{publicStringGetName(){return"Banana";}}3、(25分)importjava.io.*;publicclassTest3{publicTest3(){}publicstaticvoidmain(String[]args){java.io.ObjectOutputStreamoos=null;java.io.ObjectInputStreamois=null;try{oos
5、=newjava.io.ObjectOutputStream(newFileOutputStream("customer.dat"));oos.writeObject(newCustomer("C001","jack","010-83438475","beijing"));oos.writeObject(newCustomer("C002","Rose","021-87676364","shanghai"));oos.writeObject(newCustomer("C002","Mick","020-87676364","guangzhou"));oos.close
6、();}catch(Exceptionex){System.out.println(ex);}Customercustomer=null;try{ois=newjava.io.ObjectInputStream(newFileInputStream("customer.dat"));while((customer=(Customer)ois.readObject())!=null){System.out.println("CustomerNo:"+customer.CustomerNo);System.out.println("CustomerName:"+custo
7、mer.CustomerName);System.out.println("Phone:"+customer.Phone);System.out.println("Address:"+customer.Address);System.out.println("==========================");}ois.close();}catch(java.io.EOFExceptioneofex){System.out.println("end");}catch(Exceptionex){System.out.println(ex);}}}
此文档下载收益归作者所有