JAVA复习题1(1)

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
考试范围在第 1-6 章,重点在于第二、三、四章 一、选择题(2 分×15 题) 二、填空题(1 分×15 空) 三、程序阅读(4 小题共 30 分) 四、编程题(2 题共 25 分) 一.选择题 1.执行下列程序段后,b,x,y 的值正确的是( int x=6, y=8; boolean b; b= x < y || ++ x = = - - y; A. true , 6, 8 B. false , 7 ,7 C. true, 7, 7 D. false ,6 , 8 2. 下列语句序列执行后,j 的值是( ) 。 int j=3, i=2; while(--i != i/j) j=j+2; A. 2 B. 4 C. 6 D. 5 3.执行完下面的程序段后,k 的值是( ) 。 01 int k=0; 02 label:for(int i=1;i<10;i++) 03 { 04 for(int j=1;j<5;j++) 05 { 06 k+=i+j; 07 if(j==3) 08 break label; 09 } 10 } A. 3 B. 9 C. 12 D. 6 4. 执行完下面的程序段后,k 的值是( ) 。 01 int k=0; 02 label:for(int i=1;i<3;i++) 03 { 04 for(int j=1;j<3;j++) 05 { 06 k+=i+j; 07 08 if(i==2) 09 continue label; 10 }
20.编译和运行下面的应用程序,屏幕输出的结果是( ) public class Test { public static void main(String args[]) { A a=new A("aaaaa"); A.B b=a.new B(); System.out.println(b.inStr); } } class A { private String outStr; public A(String s) { outStr=s; } public class B { public String inStr="bbbbb"; } } A) aaaaa B)ababa C) bbbbb D) aaaaabbbbb 21.在以下程序中,显示的数字一共有()个。 int i; for(i=0; i<10; i++) { if(i%2==0) continue; System.out.println(i); } A)10 B)11 C)5 D)4 22. 1)public class Test{ 2) public static void main(String args[]){ 3) int i=0xFFFFFFF1; 4) int j=~i; 5) } 6) } 在第 5 行时,j 变量的十进制值为? () A) 0 B)1 C)14 D)15 23.在创建对象时 必须( ) A、先声明对象,然后才能使用对象 B、先声明对象,为对象分配内存空间,然后才能使用对象 C、先声明对象,为对象分配内存空间,对对象初始化,然后才能使用对象 D、上述说法都对 24.类 Teacher 和 Student 是类 Person 的子类; Person p; Teacher t; Student s;
4: try { 5: String s="ABC"; 6: byte b[]=s.getBytes(); 7: FileOutputStream file=new FileOutputStream("test.txt",true); 8: file.write(b); 9: file.close(); 10: } 11: catch(IOException e) { 12: System.out.println(e.toString()); 13: } 14: } 15: } A) ABC ABC B) ABC C)Test D) Test Test 15、java 语言是() A、机器语言 B、汇编语言 C、面向过程的语言 D、面向对象的 语言 16、下列()是反斜杠字符的正确表示 A、\ B、\\ C、\* D、 ”\ 17.执行下列语句的,a,b 的值为() int a=2; double b=3.4; a=(int)b; A、3、3 B、3、3.4 C、2、3 D、2、3.4 18.下列代码的执行结果为() public class a {public static void main(String [] args) { int a=2,b=2,c=3; String s=”abc”; System.out.println(a+b+ s +c); } } A、22abc3 B、4abc3 C、ababcc D、221233 19.下面是 findSum(int m,int n)方法的定义,方法调用 findSum(1,4)的返回 结果是( )。 int findSum(int m,int n) { int sum=1; for(int i=m;i<=n;i++) { sum*=i; } return sum; } A、 4 B、 24 C、 5 D、10
{
A() {System.out.print(“A”); } } public class B extends A { public static void main(String[] args) { B b=new B(); A a=new A(); }
} 关于上述程序代码的叙述中正确的是() A、没有输出任何信息 B、不能通过编译 C、程序通过编译,输出结果为 A D、程序通过编译,输出结果为 AA 10、下列关于修饰符说法中错误的是() A、ABSTRACT 不能与 FINAL 一起修饰同一个类 B、STATIC 方法中可以处理非 STATIC 的成员变量 C、ABSTRACT 方法必须在 ABSTRACT 类中 D、在接口中,若定义成员变量时没有修饰符,那么该成员变量默认为公有的, 最终的和静态的 11、若要在一个接口中声明一个无返回值的方法 PLAYA() ,那么声明这个方法 的形式可以是() A .public final void playa() B .public void playa() C .private void playa(double d) D .protected void playa(double d) 12.设类 B 和类 C 都不是抽象类,且类 B 是类 C 的父类。下列声明对象 x1 的语 句中不正确的是( ) 。 A. B x1=new B(); B. B x1=new C(); C. C x1=new C(); D. C x1=new B() 13、下列判断 JAVA 程序结构说法有错误的是() A、package 语句必须主在源文件的第一句 B、源文件可以没有 import 语 C、一个源文件可以有多个类定义 D、一个源文件可以定义多个 public 类 14、下面的程序第 7 行创建了一个文件输出流对象,用来向文件 test.txt 中输 出数据, 假设程序当前目录下不存在文件 test.txt,编译下面的程序 Test.java 后,将该程序运行两次,则文件 test.txt 的内容是( )。 1: import java.io.*; 2: public class Test { 3: public static void main(String args[]) {
//p, t and s are all non-null. if(t instanceof Person) { s = (Student)t; } 最后一句语句的结果是: A 将构造一个 Student 对象; B 表达式是合法的; C 表达式是错误的; D 编译时正确,但运行时错误。 25.对于下列代码: 1) class Person { 2) public void printValue(int i, int j) {//... } 3) public void printValue(int i){//... } 4) } 5) public class Teacher extends Person { 6) public void printValue() {//... } 7) public void printValue(int i) {//...} 8) public static void main(String args[]){ 9) Person t = new Teacher(); 10) t.printValue(10); 11) } 第 10 行语句将调用哪行语句?? A line 2 B line 3 C line 6 D line 7 26.要从文件" file.dat"文件中读出第 10 个字节到变量 C 中,下列哪个方法适 合? A、 FileInputStream in=new FileInputStream("file.dat"); in.skip(9); int c=in.read(); B、 FileInputStream in=new FileInputStream("file.dat"); in.skip(10); int c=in.read(); C、 FileInputStream in=new FileInputStream("file.dat"); int c=in.read(); D、 RandomAccessFile in=new RandomAccessFile("file.dat"); in.skip(9); int c=in.readByte(); 27.指出下列程序运行的结果 public class Example{ String str=new String("good"); char[]ch={'a','b','c'}; public static void main(String args[]){ Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.print(ex.str+" and "); Sytem.out.print(ex.ch); } public void change(String str,char ch[]){ str="test ok"; ch[0]='g'; }
) 。
11
} System.out.println(k); B. 5 D. 12
A. 3 C. 8 5.有以下程序 public stati c void main(String args[]) { int x=0,y=5,z=3; while(z>0&&x<4) { y=y-1; z--; x++; } System.out.println (x+”,”+y+”,”+z);} 以上程序段的输出结果是() A、3,2,0 B、3,2,-1 C、4,3,-1 D、5,-2,-5 6. 下面的程序段输出的结果是( ) 。 int i=1,b,c; int[] a=new int[3]; b=a[i]; c=b+i; SystemLeabharlann Baiduout.println(c); A. 0 B. 2 C. 1 D. 4 7. 按命令行:java Test Red Green Blue 执行下面的程序后,bar 的值是() public class Test{ public static void main(String[] args){ String foo=args[0]; String bar=args[1]; String baz=args[2]; } } A)"Green" B)"Test" C)"Red" D)"Blue " 8. 1)public class X{ 2) public static void main(String[] args){ 3) String foo="ABCDE"; 4) foo.concat("XYZ"); 5) } 6) } 当程序执行到第 5 行时 foo 的值为:( ) A) "ABCDE" B)"ABCDEXYZ" C) 值为空 D)编译出错 9.类 A 及其子类 B 定义如下: class A
相关文档
最新文档