《JavaSE程序代码阅读题(共21页).docx》由会员分享,可在线阅读,更多相关《JavaSE程序代码阅读题(共21页).docx(21页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上JavaSE程序代码阅读题()1. 阅读下面的代码,然后写出程序运行结果。 public class Test2 static boolean foo(char c) System.out.print (c); return true; ) public static void main(String argv) int i=0; for (foo(A)j foo(B)&(i0); 循环结束后,c的值是()3. 给出下面的代码:if(x0)System.out.println(first),)else if(x-3)System.out.println(second)
2、;)elseSystem.out.println(third);)x的取值在什么范围内时将打印字符串”second”4. 阅读下面程序,写出其输出:class PersonPerson()System.out.println(1);public void printValue(int i,int j)System.out.println(2);public void printValue(int i)System.out.println(3);public class Teacher extends PersonTeacher()System.out.println(4);5. 下面程序有什么
3、问题,请指正。public class Personint arr = new int ;public static void main(String a)6. 写出下列代码的输出结果。publicclassTestpublicintaMethod()staticinti=0;i+;returni;publicstaticvoidmain(Stringargs)Testtest=newTest();test.aMethod();intj=test.aMethod();System.out.println(j);7. 下列代码编译运行结果。publicclassDemopublicintadd(
4、inta,intb)tryreturna+b;catch(Exceptione)System.out.println(“catch语句块”);finallySystem.out.println(“finally语句块”);return0;publicstaticvoidmain(Stringargs)Demodemo=newDemo();System.out.println(“和是:”+demo.add(9,34);8. 下列代码编译运行结果。 public static void main(String args) try String name = null; System.out.pri
5、ntln(name.length(); catch (SQLException e) System.out.println(“有异常出现”); finally System.out.println(“执行结束”);9. 下列代码编译运行结果。 public class Animal public Animal() System.out.println(“I am an animal”);public class Cat extends Animal public Cat () System.out.println(“I am a cat”);public class Test public s
6、tatic void main (String args) Cat cat = new Cat();10. 下列代码编译运行结果。public class Person private String name; public Person() name = “小明”;public Person(String name) this(); System.out.println(“大家好,我是” + this.name);public static void main(String args) Person person = new Person(“小红”);11. 下列代码编译运行结果。 publ
7、ic static void main(String args) int i= 3; do if (i-%2 = 0) System.out.println(i); break;System.out.println(i); while (i 0);12. 下列代码编译运行结果。public class Vehicle public void run() System.out.println(“Vehicle is running”);public class Car extends Vehicle public void run() System.out.println(“Car is run
8、ning”);public static void main(String args) Vehicle vehicle = new Car(); vehicle.run();13. 下列代码编译运行结果。double i = 25;int j = 5;int result = i / j;System.out.println(result);14. 下列代码编译运行结果。public class Astatic System out printle(“a”) public A()System out printle(“b”)public class B extends Astatic Syst
9、em out printle(“1”) public B()System out printle(“2”)public class Test public static void main(String args)A ab = new B() ; ab = new B(); 15. 下列代码编译运行结果。import java.util.HashSet;import java.util.Set;public class ShortSet public static void main (String ars) Set s = new HashSet(); for(Short i=0;i100;
10、i+) s.add(i); s.remove(i-1); System.out.println(s.size(); 16. 下列代码编译运行结果。inttotal=0;for(inti=0;i4;i+)if(i=1)continue;if(i=2)break;total+=i;17. 下列代码输入2时的运行结果。publicintgetValue(inti)intresult=0;switch(i)case1:result=result+i;case2:result=result+i*2;case3:result=result+i*3;returnresult;18. 给出以下代码,请问插入什
11、么语句后可以依次打印输出数组中的每个元素?classExamplepublicstaticvoidmain(Stringargs)intarr=newint4;arr0=newint4;arr1=newint3;arr2=newint2;arr3=newint1;for(intn=0;n 0);20. 下列代码编译运行结果。public class Testpublic static changeStr(String str)str=jettech;public static void main(String args)String str=welcome;changeStr(str);Sys
12、tem.out.println(str);21. 下列代码编译运行结果。String a = a;String b = b;String c = a+b;String d = a+b;System.out.print(a=a);System.out.print(c=ab);System.out.print(d=c);System.out.print(new String(a)+b=c);22. 下列代码编译运行结果。public class SwitchTest public static void main(String args) System.out.println(switchlt(4
13、);public static int switchlt(int x) int j=1;switch (x) case 1:j+;case 2:j+;case 3:j+;case 4:j+;case 5:j+;default:j+;return j+x;23. 下列代码编译运行结果。public class HasStatic private static int x =100; public static void main(String args) HasStatic hs1 = new HasStatic();hs1.x+;HasStatic hs2 = new HasStatic();
14、hs2.x+;hs1 = new HasStatic();hs1.x+;HasStatic.x-;System.err.println(x=+x);24. 下列代码编译运行结果。public class Example public static void main(String args) int i,j;for ( i=0,j = 0; i+j0)5) j=i=2;6) System.out.print(The value of j is +j);7) k=k+1;8) i-;9) 10) 30. 下列代码编译运行结果。public class MyClass static int i;
15、public static void main(String argv) System.out.println(i); 31. 下列代码编译运行结果。public class Test3 public static void main(String args) System.out.print(100%3); System.out.print(,); System.out.println(100%3.0); 32. 下列代码编译运行结果。void complicatedExpression() int x=20, y=30; boolean b; b=x50&y60|x50&y-60|x60|
16、x-50&y5)&(s.append(there).equals(False); System.out.println(value is +s); 36. 下列代码编译运行结果。String str1 =hello;String str2=he+new String(llo);System.err.println(str1=str2);37. 下列代码编译运行结果。public class NULLpublic static void haha()System.out.print(haha);public static void main(String args) (NULL)null).ha
17、ha();38. 下列代码编译运行结果。public static void main(String args)Thread t = new Thread()public void run()pong();t.run();System.out.print(ping);static void pong()System.out.print(pong);39. 下列代码编译运行结果。public class CollectionClassifilerpublic static String classify (Set s)returnSet;public static String classify
18、 ( l)returnList;public static String classify (Collection c )returnUnknown Collection;public static void main(String args)Collection test=new Collectionnew HashSet(),/A Setnew ArrayList(),/ A Listnew HashMap().values()/Neither Set nor List;for(inti =0;itest.length;i+)System.out.print(classify(testi)
19、;40. 下面这段程序,当输入为2时返回值是多少?public static int count (int i) int result =0;switch (i) case 1:result = result + i ;case 2:result =result + i*2;case 3: result = result+i*3return result;41. 下列代码编译运行结果。String s=new String(“abcdefg”);for(int i=0;i5);System.out.println(finished);44. 下列代码编译运行结果。public class Ha
20、sStatic private static int x =100; public static void main(String args) HasStatic hs1 = new HasStatic();hs1.x+;HasStatic hs2 = new HasStatic();hs2.x+;hs1 = new HasStatic();hs1.x+;HasStatic.x-;System.err.println(x=+x);45. 下列代码编译运行结果。import java.io.*;public class B public static void main(string args)
21、 int i=12; System.out.println(i+=i-=i*=i);46. 下列代码编译运行结果。 public class Test public int method() static int x = 0; x+; return x; public static void main(String args) Test test = new Test(); test.method(); int y = test.method(); System.out.println(y); 47. 下列代码编译运行结果。public class Testpublic static void
22、 main(String args) System.out.println(6 + 6 + “aa” + 6 + 6);48. 传递4,0来运行下列代码中的方法divide(int a,int b),结果是()publicvoiddivide(inta,intb)tryintc=a/b;catch(Exceptione)System.out.print(Exception);finallySystem.out.println(Finally);49. 排查错误,请查看下列每题是否有错误并且说明错误原因1)abstract class TestUser private String name;
23、public abstract boolean isStupidName(String name) 2)public class CheckPasswordprivate void authenticate()private String s=;int 1= s.length()3)abstract class uploadFileprivate abstract String upload();4)public class ProcessDatapublic int addData(final int x)return +x;5)public class ProcessDatapublic
24、int addData(final int x)return +x;public class ProcessDatapublic static void main(String args) Other o=new Other(); new Something().addOne(o);public void addData(final Other o)o.i+;class Otherpublic int i;6)class TestClassint i;public void doSomething()System.out.print(i=+i);7)class TestClassfinal i
25、nt i;public void doSomething()System.out.print(i=+i);8)public class Somethingpublic static void main(String args) something s=new Something();System.out.print(s.doSomething() return+doSomething();public String doSomething()return Do something.9)public class TestClasspublic void submit()String str =
26、new Stringchina,usa;System.out.print(str0);str2=england;System.out.print(str2);10)public class TestFilepublic void readFile()InputStream is = this.getClas().getResourceAaStream(/config/abc.properties);int len =is.available();byte templates= new bytelen;is.read(templates);50. 下列代码编译运行结果。class HelloA
27、public HelloA() System.out.println(HelloA);System.out.println(Im A class);static System.out.println(static A);public class HelloB extends HelloA public HelloB() System.out.println(HelloB);System.out.println(Im B class);static System.out.println(static B);public static void main(String args) new Hell
28、oB();51. 下列代码编译运行后,哪个字段会被保存到文件中? class Shape public String name;class Circle extends Shape implements Serializableprivate float radius;transientint color;public static String type = Circle;52. 在执行new Child(mike)的时候都有哪些构造方法被顺序调用?class People String name;public People() System.out.print(1); public Peo
29、ple(String name) System.out.print(2);this.name = name;class Child extends People People father;public Child(String name) System.out.print(3);this.name = name;father = new People(name + :F);public Child() System.out.print(4); 53. getCustomerInfo()方法如下,try中可以捕获三种类型的异常,如果在该方法运行中产生了一个IOException,将会输出什么结果?public void getCustomerInfo() try / do something that may cause an Exception catch (java.io.FileNotFoundException ex) System.out.print(FileNotFoundException!); catch (java.io.IOException ex) System.out.print(IOException!); catch (java.lang.Exception ex) System.out.print(Ex
限制150内