2024年java基础选择测试

java基础选择测试选择题 Java 基础测试七 86 欲构造 ArrayList 类的一个实例 此类继承了 List 接口 下列哪个方法是正确的 B A ArrayList myList new Object B List myList new ArrayList C ArrayList myList new List D List myList new List 87

大家好,我是讯享网,很高兴认识大家。



【选择题】Java基础测试七

86.欲构造ArrayList类的一个实例,此类继承了List接口,下列哪个方法是正确的?( B )

A、ArrayList myList=new Object();

B、List myList=new ArrayList();

C、ArrayList myList=new List();

D、List myList=new List();

87.指出正确的表达式 (C)

A、 byte=128; (数据超出byte类型范围)

B、 Boolean=null; (只能为false或者是true)

C、 long l=0xfffL;

D、 double=0.9239d; (不需要加d)

88.指出下列程序运行的结果 ( B )

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); (ex.str,ex.ch被当作参数,所以下面的赋值没有作用)

System.out.print(ex.str+"and"); good Sytem.out.print(ex.ch); abc

}

public void change(String str,char ch[]){

str="test ok";

ch[0]='g';

}

}

A、 good and abc

B、 good and gbc

C、 test ok and abc

D、 test ok and gbc

89.运行下列程序, 会产生什么结果 ( D )

public class X extends Thread implements Runnable{

public void run(){

System.out.println("this is run()");

}

public static void main(String args[]) {

java基础选择测试

Thread t=new Thread(new X());

t.start();

}

}

A、 第一行会产生编译错误

B、 第六行会产生编译错误

C、 第六行会产生运行错误

D、 程序会运行和启动

90.要从文件"file.dat"中读出第10个字节到变量c中,下列哪个方法适合? (D)

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();

91.Java编程所必须的默认引用包为( B )

A. java.sys包

B. java.lang包

C. java.util包 (工具包)

D.以上都不是

92.下面语句在编译时不会出现警告或错误的是( 全错 )

A. float f=3.14; (数字后面要加f)

B. char c=”c”; (单引号)

C. Boolean b=null; (只能为false或者是true)

D. int i=10.0; (10.0不是int类型)

93.下面不是合法标识符的是( A )

A. 2ofUS (不能以数字开头)

B. giveMes C. whataQuiz D. $d2000_

94.下面哪一个是合法的数组声明和构造语句( C )

A. int[] ages = [100];

B. int ages = new int[100];

C. int[] ages = new int[100];

D. int() ages = new int(100);

95.下面说法不正确的是( C )

A. 一个子类的对象可以接收父类对象能接收的消息;

B. 当子类对象和父类对象能接收同样的消息时,它们针对消息产生的行为可能不同;

C. 父类比它的子类的方法更多; (子类继承父类的非私有属性和方法,并且可以重写方法)

D. 子类在构造函数中可以使用super( )来调用父类的构造函数;

96.给出下面代码段, 哪行将引起一个编译时错误?( D )

1) public class Test {

2) int n = 0;

3) int m = 0;

4) public Test(int a) { m=a; }

5) public static void main(String arg[]) {

6) Test t1,t2;

7) int j,k;

8) j=3; k=5;

9) t1=new Test(); 没有传参

10) t2=new Test(k);

11) }

12) }

A. 行1 B. 行4 C. 行6 D. 行9

97.下面程序中类ClassDemo中定义了一个静态变量sum,分析程序段的输出结果。

( C )

class ClassDemo {

public static int sum=1;

public ClassDemo() {

sum = sum + 5; //sum=6

}

}

public class ClassDemoTest{

public static void main(String args[]) {

ClassDemo demo1=new ClassDemo();

ClassDemo demo2=new ClassDemo();

System.out.println(demo1.sum); //调用sum方法,此时sum=6,执行sum=sum+5;则sum=11

}

}

A. 0 B. 6 C. 11 D. 2

98.下面这些类型的应用,那个不使用Java语言来编写? ( A )

A)JavaScript

B)Applet

C)Servlet

D)Java Swing

99.声明成员变量时,如果不使用任何访问控制符(public, protected, private),则以下哪种类型的类不能对该成员进行直接访问 ( D )

A)同一类

B)同一包中的子类

C)同一包中的非子类

D)不同包中的子类

100.下列哪种异常是检查型异常,需要在编写程序时声明 ( C )

A)NullPointerException

B)ClassCastException

C)FileNotFoundException

小讯
上一篇 2025-01-03 08:02
下一篇 2024-12-29 16:44

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/9237.html