题目内容

写出下列程序段的运行结果classA{doublef(doublex,doubley){returnx*y;}}classBextendsA{doublef(doublex,doubley){returnx+y;}}publicclassTest{publicstaticvoidmain(Stringargs[]){Bobj=newB();System.out.println("Theprogramoutputis"+obj.f(4,6));}}

查看答案
更多问题

写出下列程序段的运行结果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);}}}}

答案查题题库