题目内容

写出下列程序段的运行结果publicclassUnchecked{publicstaticvoidmain(String[]args){try{method();}catch(Exceptione){System.out.println("A");}finally{System.out.println("B");}}staticvoidmethod(){try{wrench();System.out.println("C");}catch(ArithmeticExceptione){System.out.println("D");}finally{System.out.println("E");}System.out.println("F");}staticvoidwrench(){thrownewNullPointerException();}}

查看答案
更多问题

写出下列程序段的运行结果class father{void speak(){System.out.println("I am father!");}}public class son extends father{void speak(){super.speak();System.out.println("I am son!");}public static void main(String args[]){son cxz=new son();cxz.speak();}}

/*** 往文件中依次写入3名员工的信息,* 每位员工有工龄和姓名两个字段 然后按照* 第二名,第一名,第三名的先后顺序读取员工信息*/import java.io.File;import java.io.RandomAccessFile;public class RandomAccessFileTest {public static void main(String[] args) throws Exception {Employee employee1 = new Employee(5, "张三");Employee employee2 = new Employee(6, "lisi");Employee employee3 = new Employee(7, "James");File file = new File("employee.txt");if(!file.exists()){(1) //如果文件不存在,则新建文件}//设置文件的打开方式为读写RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");randomAccessFile.writeChars(employee1.getName());//写出第一个员工的姓名randomAccessFile.writeInt(employee1.getWork_age());//写出第一个员工的工龄randomAccessFile.writeChars(employee2.getName());randomAccessFile.writeInt(employee2.getWork_age());randomAccessFile.writeChars(employee3.getName());randomAccessFile.writeInt(employee3.getWork_age());randomAccessFile.close();//关闭文件RandomAccessFile raf2 =(2)//以只读方式打开文件(3)//跳过第一个员工String strName2 = "";for(int i=0;i

//打印1000之内的完数(一个数如果恰好等于除它本身外的因子之和,这个数就称为完数//例如6=1+2+3,6的因子是1,2,3)。public class Wanshu{public static void main (String args[ ]){int sum,i,j;for(i=1;i<=1000;i++){for(j=1,sum=0;j<=i/2;j++){(1) {sum=sum+j;}}if(2) {System.out.printf("%8d是一个完数%n",i);}}}}

//线程A等待线程B的执行public class Dengdai{public static void main(String args[ ]){KThread a=new KThread ();a.threadA.start();}}class KThread implements Runnable{Thread threadA,threadB;String content[ ]={"今天晚上,","六点钟开始","在201实验室,","全班同学","上java实验!"};KThread(){(1)(2)threadB.setName("老师");}public void run(){if(Thread.currentThread()==threadA){System.out.println("我等"+threadB.getName()+"讲完我在提问!");threadB.start();while(threadB.isAlive()==false){}try{ (3) //线程threadA开始等待threadB结束}catch(InterruptedException e){}System.out.printf("\n老师:\"这个问题该怎么解决,谢谢老师\"");}else if(Thread.currentThread()==threadB){System.out.println(threadB.getName()+"说:");for(int i=0;i

答案查题题库