JAVA复习题1(1)
更新时间:2024-02-02 18:08:01 阅读量: 教育文库 文档下载
- java复合数据类型推荐度:
- 相关推荐
考试范围在第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 }
。 。 )。 )) 11 }
System.out.println(k);
A. 3 B. 5 C. 8 D. 12 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;
System.out.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)\ B)\C)\ D)\
8. 1)public class X{
2) public static void main(String[] args){ 3) String foo=\ 4) foo.concat(\ 5) } 6) }
当程序执行到第5行时foo的值为:( ) A) \B)\C) 值为空 D)编译出错 9.类A及其子类B定义如下: class A
{ 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[]) {
4: try {
5: String s=\6: byte b[]=s.getBytes();
7: FileOutputStream file=new FileOutputStream(\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
20.编译和运行下面的应用程序,屏幕输出的结果是( ) public class Test {
public static void main(String args[]) { A a=new A(\ 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=\ } }
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;
//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.要从文件\文件中读出第10个字节到变量C中,下列哪个方法适合?
A、 FileInputStream in=new FileInputStream(\in.skip(9); int c=in.read(); B、 FileInputStream in=new FileInputStream(\in.skip(10); int c=in.read(); C、 FileInputStream in=new FileInputStream(\int c=in.read(); D、 RandomAccessFile in=new RandomAccessFile(\int c=in.readByte();
27.指出下列程序运行的结果 public class Example{
String str=new String(\ 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+\ Sytem.out.print(ex.ch); }
public void change(String str,char ch[]){ str=\ ch[0]='g'; }
}
A、 good and abc B、 good and gbc C、test ok and abc D、 test ok and gbc
28..构造BufferedInputStream的合适参数是哪个? A BufferedInputStream B BufferedOutputStream C FileInputStream D FileOutputStream
29. 应用程序的main方法中有以下语句,则输出的结果是 ( )。 Hashtable hashtable=new Hashtable(); hashtable.put(\
hashtable.put(\System.out.println(hashtable.get(\A) aaa B) bbb C) 200 D) 3 二.填空题
1.java 应用程序中有一个main()方法,它前面有三个修饰符是_public_ 、 __static 、 _void_ 2.设x为float型变量, y为 double型变量, a为 int型变量,已知 x=2.5f, a=7 ,y=4.22 则表达式x+a%3*(int)x%(int)y的值为_________________ 3.JAVA语言的各数据类型之间提供两种数据类型转换,自动数据类型转换和____________
4.break和continue语句都可以用在循环语句中,但break还可以用在_语句中
5.JAVA源文件名后缀名为_____.java__编译好的字节码文件后缀名为_.class___
6.接口中只有_成员方法_和_成员变量_。
7.子类继承父类,如果要调用父类的构造方法应使用__super()__。
8.面向对象的软件开发方法用 __class(类)___把数据和基于数据的操作封装在一起。
9.阅读程序,完成下面的程序填空: (1) B ,(2) public 。程序的输出结果是 5
6 。
01 public class A implenents B{ 02 static int m;
03 public static void main(String[] args){ 04 m= (1) .k;
05 System.out.println(m); 06 A a=new A(); 07 a.myMethod(); 08 }
09 (2) void myMethod(){ System.out.println(++m);}
10 }
11 interface B{ 12 int k=5;
13 void myMethod(); 14 }
10. 短路逻辑运算符包括_&&_和__||_,三目运算符是___? :______。
11.现有一个字节码文件为OA$1.class,则这个类是______内部类__________。
12.下面程序的功能是:统计个位数为6,且能被3整除的3位数的个数。请在 处选择正确答案将程序补充完整。 public class myclass{
public static void main(String args[]){ int n, c; c=0;
for(n=100; n<=999;n++) If (n==6 && n%3==0)
c++;
}
13.abstract方法______不能__(不能或能)与final并列修饰同一个类 14.文件操作中经常需要的是随机访问, java中的_randomaccessFile类提供了随机访问文件的功能.
15.下列程序实现从控制台输入并读取输出字符串. 请将程序补充完整 import java.io.*;
public class CharInput {
public static void main(String args[]) throws java.io.IOException }
String s;
inputStreamReader ir;
BufferedReader in; ir=new_InputStreamReader(System.in); in=new__BufferedReader(ir); while ((s=in.readLine_)!=null) {
System.out.println(“Read;”+s); } } }
16. 填写空语句: 打印下列图案
********* public class mathtest ******* {
***** public static void main(String[] args)
*** {
for(int i=0;_i<5___________;i++) {
for(int j=0;j<=i;j++) System.out.print(\\
for(int k=0;_k<9-2*i__;k++)
System.out.print(\
System.out.println();
} } } 17.在java源程序的类头中使用关键字__implements__声明该类实现某个接口。 18.__object__类是所有Java包中的类、用户自定义类的直接或间接父类。 19. _单链表是由若干个称为结点的对象组成的一种数据结构,每个结点有一个数据和下一个结点对象的引用。
20.文件随机访问类RandomAccessFile中的方法seek(int pos)可将读写指针_____(移动到/跳过)指定的位置pos,方便文件的读写。 三、程序阅读题:
}1、阅读以下程序,输出结果为_1.23_______。 class Q1{
public static void main(String args[ ]){ double d=1.23;
Dec dec=new Dec( ); dec.decrement(d);
System.out.println(d); } }
classs Dec{
public void decrement(double decMe){ decMe = decMe - 0.1;
} }
2、以下程序的输出结果为_没有输出______。 public class Short{
public static void main(String args[ ]) { StringBuffer s = new StringBuffer(\ if((s.length( )>=5)&& (s.append(\equals(\
System.out.println(\ } }
3、以下程序段的输出结果为_Message four___。 int x=0,y=4, z=5; if ( x>2){ if (y<5){
System.out.println(\
} else {
System.out.println(\ } }
else if(z>5){
System.out.println(\ } else {
System.out.println(\ }
4.类A及其子类B定义如下: class A {
public String toString() {
Return ”a”; } }
class B extends A {
public String toString() {
System.out.print(super.toString()); return “b”; }
public static void main(String[] args) {
B b=new B();
System.out.ptintln(b.toString());
} }
那么程序的执行结果为______ab_________________ 5.类 Test3定义如下:
public class Test3 {
public static void main(String[] ars) {
String s1=”abcdef”;
String s2=s1.replace(‘c’,’h’); s1=”ABCDEF”;
System.out.println(s1+s2); }
}
正在阅读:
JAVA复习题1(1)02-02
高中会考英语词汇表01-12
TDOA定位12-08
2016年《纳税服务规范》考试试题及参考答案精华版备考资料03-26
句式变换考点知识清单06-26
红楼梦阅读讲义4(教师版16-20回)09-22
博迪《投资学》(第9版)课后习题-证券是如何交易的(圣才出品)03-21
大学生公正世界信念与自尊在儿童期虐待与主观幸福感关系中的中介作用_田志鹏_刘爱书08-14
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 复习题
- JAVA
- 《巧设美术作业,构建学的课堂》 - 图文
- 廉洁文化解说稿
- 纸箱印刷机及配件项目可行性研究报告 - 图文
- 生命伦理案例讨论和模拟审查
- 2011年晚会串词
- 国网集中器载波模块RTB-GW(v1.0)修改说明
- 土木工程应用数学课程改革方案
- 加拿大ETSB教育局国际学生计划手册 - 图文
- 纬地使用方法
- 2017届电气毕业生顶岗实习计划(10.11)
- 精品人教版初中地理会考复习提纲(四册书全)
- Revit困难及问题的解决措施 - 图文
- 叠加器常用芯片有哪些?
- 2015版环境管理体系标准关注点南京廖华
- 西方语言学流派复习资料
- 华东师大版七年级数学下册多边形单元测试题 - 图文
- 风电科技产业园检测平台3、4号房屋面钢结构施工组织设计
- 上海海事大学 国际航运管理考试整理 - 图文
- 贵州省黔东南州2017年中考英语试卷(word版,精校无误有答案)
- 社会主义市场经济理论与实践案例3