Java程序设计第三次作业题及答案
第3次作业一、程序阅读题(本大题共40分,共 10 小题,每小题 4 分)1. public class test{ static StringBuffer sb1=new StringBuffer("Hello"); static StringBuffer sb2=new StringBuffer("Hello"); public static void main(String args[]){aMethod(sb1,sb2); System.out.println("sb1 is "+sb1);?System.out.println("sb2 is "+sb2); }?public static void aMethod(StringBuffer sb1,StringBuffer sb2){ sb2.append(" there");?sb1=sb2; } }2. public class test{?
?static int arr[] ={1,2,3,4,5};?public static void main(String args[])?{?System.out.println(arr[]); } }
3. public class Test{ public static void main(String[] args){ String foo=args[0];?String bar=args[1]; String baz=args[2]; System.out.println(baz);?}?} 如果执行语句 java Test Red Green Blue 后结果为4. 阅读以下程序:若执行命令:java AB heLLO,则输出为 ______ 。5. 请写下程序的输出结果:6. import java.io.*;public class Ppvg{?public static void main(String argv[]){? ?Ppvg p = new Ppvg( ); ? ?p.fliton( ); ?} ?public int fliton( ){? ?try{? ? ?FileInputStream din = new FileInputStream("P.java"); ? ? ?din.read( ); ?}catch(IOException ioe){? ? System.out.println("flytwick");? ? return 99;?}?finally{ ? ?System.out.println("fliton");?}?return -1; } } 如果P.java文件不存在,输出结果是什么?7. 指出下列程序运行的结果?public class BreakTest { public static void main(String args[] ) {?int count; for ( count = 1; count <= 10; count++ ) {if ( count == 8 ) break;?System.out.println( count );?}?}?}8. public class Leaf{?private int i=0;?Leaf increment( ){?i++;?return this;?}?void print( ){?System.out.println(“i=”+i);?}?public static void main(String args[]){?Leaf x=new Leaf( );?x.increment( ).increment( ).increment( ).print( );?} }9. 写出程序运行的结果.?class Parent{?void printMe( ){?System.out.println(“I’m parent”); }?}?class Child extends Parent{?void printMe( ){?System.out.println(“I’m child”);?} void printAll( ){ super.printMe( ); this.printMe( );?printMe( );?}?}?public class Test_this{?public static void main(String args[]){?Child myc=new