写出下列程序段的运行结果public class Test{public static void main(String[]args){int x;int a[]={0,0,0,0,0,0};calculate(a,a[5]);System.out.println("the value of a[0] is "+a[0]);System.out.println("the value is a[5] is "+a[5]);}static int calculate(int x[],int y){for(int i=1;i
查看答案
写出下列程序段的运行结果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 LEN){name = name.substring(0, LEN);}else{while(name.length() < LEN){name = name + "$";}}this.name = name;}public int getWork_age() {return work_age;}public String getName() {return name;}}