《JAVA语言程序设计Ⅰ》在线平时作业3-00001
试卷总分:100 得分:100
一、单选题 (共 20 道试题,共 60 分)
1.65. 已知有下列类的说明,则下列哪个语句是正确的? public class Test { private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg[]) { Test t = new Test(); } }
A.t.f;
B.this.n;
C.Test.m;
D.Test.f;
2.在程序的源文件开始处有下面一行程序: package awt;
A.结果是一个编译错误,因为Java已经定义了一个awt包
B.说明这个文件里的所有的类都应该包含在java.awt包里
C.说明这个文件里的所有的类都应该包含在自己定义的awt包里
D.导入你自己定义的awt包里的所有类
3.已知如下的命令执行 java MyTest a b c 请问哪个语句是正确的?
A.args[0] = "MyTest a b c"
B.args[0] = "MyTest"
C.args[0] = "a"
D.args[1]= 'b'
4.以下由do-while语句构成的循环执行的次数是( )。 int k = 0; do { ++k; }while ( k < 1 );
A.一次也不执行
B.执行1次
C.无限次
D.有语法错,不能执行
5.已知如下代码: boolean m = true; if ( m = false ) System.out.println("False"); else System.out.println("True"); 执行结果是什么?
A.False
B.True
C.编译时出错
D.运行时出错
6.设有下面的一个类定义: class AA { static void Show( ){ System.out.println("我喜欢Java!"); } } class BB { void Show( ){ System.out.println("我喜欢C++!"); } } 若已经使用AA类创建对象a和BB类创建对象b,则下面哪一个方法调用是正确的:( )
A.Show( ) b.Show( )
B.AA.Show( ) BB.Show( )
C.AA.Show( ) b.Show( )
D.Show( ) BB.Show( )
7.下列哪个选项的java源文件代码片段是不正确的?
A.package testpackage; public class Test{ }
B.import java.io.*; package testpackage; public class Test{ }
C.import java.io.*; class Person{ } public class Test{ }
D.import java.io.*; import java.awt.*; public class Test{ }
8.下面语句返回的数据类型是什么? (short)10/10.2*2;
A.int
B.double
C.float
D.short
9.给出下列代码,如何使成员变量m 被方法fun()直接访问? class Test { private int m; public static void fun() { ... } }
A.将private int m 改为protected int m
B.将private int m 改为 public int m
C.将private int m 改为 static int m
D.将private int m 改为 int m
10.已知表达式int m[] = {0, 1, 2, 3, 4, 5, 6 }; 下面哪个表达式的值与数组下标量总数相等?
A.length()
B.length
C.length()+1
D.length+1
11.Person, Student 和Teacher 都是类名。这些类有以下继承关系。 Person | -------------------- | | Student Teacher 并且在Java源代码中有如下表达式: Person p = new Student(); 如下哪个语句是正确的?
A.这条语句是合法的
B.这条语句是不合法的
C.编译时出错
D.编译正确但运行时出错
12.下面哪一个类可以访问foo包中的所有变量? package foo; class a{int c} class b{private int d} class c{public int e}
A.class a
B.class b
C.class c
D.都不能
13.下面程序的输出结果是什么? class Foo{ static void change(String s){ s=s.replace('j','l'); } public static void main(String args[]){ String s="java"; change(s); System.out.println(s); } }
A.lava
B.java
C.编译错误
D.运行时出现异常
14.有下面的类: public class Example{ static int x[]=new int[15]; public static void main(String args[]){ System.out.println(x[5]); } } 下面的那些说法是正确的。
A.编译时出错
B.运行时出错
C.输出0
D.输出null
15.下列程序的功能是在监控台上每隔一秒钟显示一个字符串“Hello”,能够填写在程序中下划线位置,使程序完整并能正确运行的语句是 public class Test implements Runnable{ public static void main(String args[]){ Test t=new Test(); Thread tt=new Thread(t); tt.start(); } public void run(){ for(;;){ try{
A.sleep(1000) InterruptedException
B.sleep(1000) RuntimeException
C.Thread.sleep(1000) RuntimeException
D.Thread.sleep(1000) InterruptedException
16.下列语句序列执行后,k 的值是( )。 int x=6, y=10, k=5; switch( x%y ) { case 0: k=x*y; case 6: k=x/y; case 12: k=x-y; default: k=x*y-x; }
A.60
B.54
C.0
D.5
17.下列代码中,将引起一个编译错误的行是 1)public class Test{ 2) int m,n; 3) public Test() {} 4) public Test(int a) {m=a;} 5) public static void main(String args[]){ 6) Test t1,t2; 7) int j,k; 8) j=0;k=0; 9) t1=new Test(); 10) t2=new Test(j,k); 11) } 12
A.第3行
B.第5行
C.第6行
D.第10行
18.给出下列代码,则数组初始化中哪项是不正确的? byte[] array1,array2[]; byte array3[][]; byte [][] array4;
A.array2 = array1
B.array2=array3
C.array2=array4
D.array3=array4
19.下列语句序列执行后,k的值是( )。 int j=8, k=15; for( int i=2; i!=j; i++ ) { j-=2; k++; }
A.15
B.16
C.17
D.18
20.下面的哪些程序段可以正确地获得从命令行传递的参数的个数?
A.int count = args.length;
B.int count = args.length-1;
C.int count=0; while(args[count]!=null) count++;
D.int count=0;while (!(args[count].equals(“”))) count++;
二、多选题 (共 10 道试题,共 40 分)
21.String s=”Example String”; 下面哪些语句是正确的?
A.s>>>=3;
B.int i=s.length();
C.s[3]=”x”;
D.String short_s=s.trim();
E.String t=”root”+s;
22.如果有以下代码,哪几个数字能产生输出 "Test2" 的结果? Switch(x){ case 1: System.out.println("Test1"); case 2: case 3: System.out.println("Test2"); break;} System.out.println("Test3"); }
A.0
B.1
C.2
D.3
23.已知如下类定义: class Base { public Base (){ //... } public Base ( int m ){ //... } protected void fun( int n ){ //... } } public class Child extends Base{ // member methods } 如下哪句可以正确地加入子类中?
A.private void fun( int n ){ //...}
B.void fun ( int n ){ //... }
C.protected void fun ( int n ) { //... }
D.public void fun ( int n ) { //... }
24.假定文件名是“Fred.java”,下面哪个是正确的类声明。
A.public class Fred{ public int x = 0; public Fred (int x){ this.x=x; } }
B.public class fred{ public int x = 0; public Fred (int x){ this.x=x; } }
C.public class Fred extends MyBaseClass{ public int x = 0; }
25.下面的哪些程序片断可能导致错误。
A.String s="Gonewiththewind"; String t="good"; String k=s+t;
B.String s="Gonewiththewind"; String t; t=s[3]+"one";
C.String s="Gonewiththewind"; String standard=s.toUpperCase();
D.String s="homedirectory"; String t=s-"directory".
26.已知如下代码: switch (m) { case 0: System.out.println("Condition 0"); case 1: System.out.println("Condition 1"); case 2: System.out.println("Condition 2"); case 3: System.out.println("Condition 3");break; default: System.out.println("Other Condition"); } 当m 的
A.0
B.1
C.2
D.3
E.4
F.以上都不是
27.下面代码执行后的输出是什么? outer: for(int i=0;i<3; i++) inner: for(int j=0;j<2;j++) { if(j==1) continue outer; System.out.println(j+ “ and “+i); }
A.0 and 0
B.0 and 1
C.0 and 2
D.1 and 0
E.1 and 1
F.1 and 2
G.2 and 0
H.2 and 1
I.2 and 2
28.你怎样从下面main()的调用中访问单词“kiss”? java lyrics a kiss is but a kiss
A.args[0]
B.args[1]
C.args[2]
D.args[3]
E.args[4]
F.args[5]
29.请选出创建数组的正确语句。
A.float f[][] = new float[6][6];
B.float []f[] = new float[6][6];
C.float f[][] = new float[][6];
D.float [][]f = new float[6][6];
30.已知如下类说明: public class Test { private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg[]) { Test t = new Test(); // 程序代码… } } 如下哪个使用是正确的?
A.t.f
B.this.n
C.Test.m
D.Test.n