《Java 语言程序设计》阶段测试题

更新时间:2023-11-13 01:01:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

《Java 语言高级程序设计一》阶段测试题(一)

题号 答案 题号 答案 题号 答案 1 A 10 ACD 2 E 11 E 3 A 12 CD 4 AE 13 B 5 E 14 D 6 D 15 B 7 A 16 C 8 D 17 C 9 AE 18 D (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) 11 F T T F T T F T F T F

一、选择题(共18题,每题5分,共90分)

试题1:当你编译运行下列程序代码,会得到什么结果? public class Sample {

public static void main(String args[]) {

int i = 4;

float f = 4.3; double d = 1.8; int c = 0;

if (i == f) c++;

if (((int) (f + d)) == ((int) f + (int) d)) c += 2; System.out.println(c); } }

a) 这段代码不能通过编译。 b) 0输出在屏幕中。 c) 1输出在屏幕中。 d) 2输出在屏幕中。 e) 3输出在屏幕中。

试题2:当你编译运行下列程序代码,会得到什么结果? class Mystery {

String s;

public static void main(String[] args) {

Mystery m = new Mystery(); m.go(); }

void Mystery() {

s = \ }

1

void go() {

System.out.println(s); } }

a) 这段代码不能通过编译。

b) 这段代码能通过编译,但是运行时会有异常。 c) 这段代码能运行,但不输出任何结果。

d) 这段代码能运行并且输出constructor在屏幕中。 e) 这段代码能运行并且输出null在屏幕中。

试题3:当你编译运行下列程序代码,会得到什么结果? private class Base{ Base(){ int i = 100;

System.out.println(i); } }

public class Pri extends Base{ static int i = 200;

public static void main(String argv[]){ Pri p = new Pri();

System.out.println(i); } }

a) 这段代码不能通过编译。 b) 输出200。

c) 输出100和200。 d) 输出100。

试题4:考虑以下代码, 在注释的位置,插入哪条方法声明不会引起编译错误?

public class Qdd1f {

public long sum(long a, long b) { return a + b; } // 在这里插入新的方法 }

a) public int sum(int a, int b) { return a + b; } b) public int sum(long a, long b) { return 0; } c) abstract int sum();

2

d) private long sum(long a, long b) { return a + b; } e) public long sum(long a, int b) { return a + b;} 试题5:当你编译运行下列程序代码,会得到什么结果? class Base {

int i;

Base() { add(1); }

void add(int v) { i += v; }

void print() { System.out.println(i); } }

class Extension extends Base {

Extension() { add(2); } void add(int v) { i += v*2; } }

public class Qd073 {

public static void main(String args[]) {

bogo(new Extension()); }

static void bogo(Base b) {

b.add(8); b.print(); } }

a) 9 b) 18 c) 20 d) 21 e) 22 试题6当你编译运行下列程序代码,会得到什么结果? class Base{

void test() { System.out.println(\ } }

public class Child extends Base {

void test() { System.out.println(\ } static public void main(String[] a) {

Base baseObj = new Child(); baseObj.test(); } }

a) Child.test()

Base.test()

3

b) Base.test()

Child.test() c) Base.test() d) Child.test()

e) Runtime error. java.lang.ClassCastException 试题7当你编译运行下列程序代码,会得到什么结果? 01: class Base 02:{

03: final int MAX_SIZE; 04: Base(){

05: MAX_SIZE = 10;//初始化一个值 06: } 07:

08: void test() { 09: MAX_SIZE++;

10: System.out.println(\11: } 12: 13:}

a) 在第9行产生编译错误:不能改变常量MAX_SIZE的值 b) 在第3行产生编译错误:不能定义空常量MAX_SIZE c) 在第5行产生编译错误:不能为空常量MAX_SIZE赋值 d) 编译通过

试题8考虑下列代码,将产生什么结果?///值得传递 public class Test {

public static void main(String args[]) { String a = new String(\String b = new String(\Test.swap(a,b);

System.out.println(\}

static void swap (String a, String b) {

a=a+\b=a; } }

4

a. a is One more

b is Two b. a is One

b is One

c. a is One more

b is One more d. a is One

b is Two

e. a is One more

b is Two more

试题9下列哪行语句不会产生编译警告和错误? a) float f=0; b) char c=\ c) byte b=157; d) boolean f=null; e) int i=10;

试题10 下列哪一个是合法的Java标识符? a) _1_ b) int c) byte1 d) $Value e) goto f) 3Value

试题11当你编译运行下列程序代码,会得到什么结果? 1:public class Base{ 2:

3: private void test() { 4:

5: String aStr = \

6: String bStr = new String();

7: String cStr = new String(\8: String dStr = aStr;

9: System.out.println(aStr + \10: } 11:

12: static public void main(String[] a) {

5

本文来源:https://www.bwwdw.com/article/k4qv.html

Top