正确答案:C
西交《Java语言》在线作业-00002
试卷总分:100 得分:100
一、单选题 (共 30 道试题,共 60 分)
1.在创建对象时必须()
A.先声明对象,然后才能使用对象
B.先声明对象,为对象分配内存空间,然后才能使用对象
C.先声明对象,为对象分配内存空间,对对象初始化,然后才能使用对象
D.其它说法都对
正确选项:--------
2.指出下列程序运行的结果 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'; } } ( )
正确答案:C
A.good and abc
正确答案:A
正确选项:--------
B.good and gbc
正确选项:--------
C.test ok and abc
D.test ok and gbc
正确答案:A
3.整型数据类型中,需要内存空间最少的是()
A.short
B.long
C.int
D.byte
随机答案:ABCD
4.Character流与Byte流的区别是()
A.每次读入的字节数不同
B.前者带有缓冲,后者没有
C.前者是字符读写,后者是字节读写
D.二者没有区别,可以互换使用
正确选项:--------
5.类Test1定义如下: 1.public class Test1{ 2. public float aMethod(float a,float b){ } 3. 4.} 将以下哪种方法插入行3是不合法的。( )
正确答案:A
A.public float aMethod(float a, float b,float c){ }
正确答案:C
B.public float aMethod(float c,float d){ }
正确答案:B
C.public int aMethod(int a, int b){ }
正确答案:B
D.private float aMethod(int a,int b,int c){ }
正确答案:A
6.关于以下application的说明,正确的是( ) 1. class StaticStuff 2. { 3. static int x=10; 4. static { x+=5;} 5. public static void main(String args[ ]) 6. { 7. System.out.println(“x=” + x); 8. } 9. static { x/=3;} 10. }
正确选项:--------
A.4行与9行不能通过编译,因为缺少方法名和返回类型
B.9行不能通过编译,因为只能有一个静态初始化器
C.编译通过,执行结果为:x=5
D.编译通过,执行结果为:x=3
正确答案:A
7.有以下程序片段,下列哪个选项不能插入到行1。( ) 1. 2.public class Interesting{ 3.//do sth 4. }
正确答案:A
A.import java.awt.*;
B.package mypackage;
C.class OtherClass{ }
D.public class MyClass{ }
正确选项:--------
8.给出下面代码: 1) class Parent { 2) private String name; 3) public Parent(){} 4) } 5) public class Child extends Parent { 6) private String department; 7) public Child() {} 8) public String getValue(){ return name; } 9) public static void main(String arg[]) { 10) Parent p = new Parent(); 11) } 12) } 那些行将引起错误?( )。。
正确答案:B
A.第3行
B.第6行
C.第7行
D.第8行
正确答案:C
9.类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对象;
正确答案:D
B.表达式是合法的;
C.表达式是错误的;
D.编译时正确,但运行时错误。
正确选项:--------
10.对方法main的第1行定义正确的是( )。
A.public main( String arg [ ] )
B.public void main( String arg [ ] )
正确答案:D
正确答案:C
C.public static void main( String arg [ ] )
D.public static void main( String args [ ] )
正确答案:D
11.Java application中的主类需包含main方法,main方法的返回类型是什么?( )
A.int
B.float
C.double
正确答案:C
随机答案:ABCD
D.void
正确答案:D
12.对于下列代码:
1) class Person {
2) public void printValue(int i, int j) {//... }
正确答案:B
3) public void printValue(int i){//... }
正确答案:B
4) }
5) public class Teacher extends Person {
随机答案:ABCD
6) public void printValue() {//... }
正确答案:A
7) public void printValue(int i) {//...}
正确答案:B
8) public static void main(String args[]){
正确答案:B
9) Person t = new Teacher();
10) t.printValue(10);
11) }
第10行语句将调用哪行语句??
A.line 2
B.line 3
C.line 6
D.line 7
正确选项:--------
13.给出下面代码: public class test{ static int a[] = new a[10]; public static void main(String args[]) { System.out.println(arr[10]); } } 那个选项是正确的?( )
正确答案:B
A.编译时将产生错误;
B.编译时正确,运行时将产生错误;
C.输出零;
D.输出空。
正确答案:C
14.Java语言具有许多优点和特点,哪个反映了Java程序并行机制的特点?()
A.安全性
B.多线性
C.跨平台
D.可移植
正确答案:D
15.下面哪些选项是正确的main方法说明? ( )
A.public main(String args[])
B.public static void main(String args[])
正确答案:B
正确选项:--------
C.private static void main(String args[])
D.void main()
正确答案:D
16.以下选项中循环结构合法的是( )
A.while (int i<7) { i++; System.out.println(“i is “+i); }
正确答案:A
B.int j=3; while(j) { System.out.println(“ j is “+j); }
正确答案:D
C.int j=0; for(int k=0; j + k !=10; j++,k++) { System.out.println(“ j is “+ j + “k is”+ k); }
正确答案:B
D.int j=0; do{ System.out.println( “j is “+j++); if (j = = 3) {continue loop;} }while (j<10);
随机答案:ABCD