达内java2015.11第一次月考(附答案).doc

发布时间:2015-12-30 23:09:08



在线考试 本次考试得分:96.0

1.

(单选)下列属于不合法Java标识符的是()。

o  A.

_mem

o  B.

12a

o  C.

M12

o  D.

$12

正确答案:B

2.

(单选)程序的执行结果是: public class Test { public static void main(String[] args){ System.out.println(""+'a'+1); } }

o  A.

98

o  B.

a1

o  C.

971

o  D.

197

正确答案:B

3.

(单选)下列Java标识符,错误的是()

o  A.

_sys_varl

o  B.

$change

o  C.

User_name

o  D.

1_file

正确答案:D

4.

(单选)请看下列代码: public String makinStrings() { String s = "Fred"; s = s + "47"; s = s.substring(2, 5); s = s.toUpperCase(); return s.toString(); } 调用makinString方法,得到的字符串长度是:

o  A.

1

o  B.

2

o  C.

3

o  D.

4

正确答案:C

5.

(单选)分析如下代码,输出结果为()。 public static void main(String[] args) { int i = 0; boolean re = false; re = ((++i) + i == 2) ? true : false; System.out.println("i=" + i + ",re="+re); }

o  A.

i=1,re=true

o  B.

i=0,re=true

o  C.

i=1,re=false

o  D.

i=0,re=false

正确答案:A

6.

(单选)下列代码的运行结果是() public static void main(String[] args) { String str = "420"; str += 42; System.out.print(str); }

o  A.

42

o  B.

420

o  C.

462

o  D.

42042

正确答案:C

7.

(单选)请看下列代码: public static void main(String[] args) { <插入代码> System.out.println(s); } 如果程序输出的结果是4247,那么在<插入代码>处应该填入代码是()。

o  A.

String s = "123456789"; s = (s-"123").replace(1,3,"24") - "89";

o  B.

StringBuffer s = new StringBuffer("123456789"); s.delete(0,3).replace( 1,3, "24").delete(4,6);

o  C.

StringBuffer s = new StringBuffer("123456789"); s.delete(0,3).replace( 1,3, "24").delete(4,6);

o  D.

StringBuilder s = new StringBuilder("123456789"); s.substring(3,6).delete( 1 ,2).insert( 1, "24");

正确答案:B

8.

(单选)下列关于IDE开发环境Eclipse,说法错误的是:()。

o  A.

Eclipse可以通过插件(plugin)的方式扩展其功能。

o  B.

Eclipse联盟是由IBM公司捐资组建的。

o  C.

Eclipse使用了SWT图形界面技术。

o  D.

Eclipse的运行不需要有JRE的支持。

正确答案:B

9.

(单选)下列赋值语句中,正确的是()。

o  A.

byte b1 = 10, b2 = 20; byte b=b1+b2;

o  B.

byte b1 = 10, b2 = 20; byte b=~b1;

o  C.

byte b1 = 10, b2 = 20; byte b=b1>>1;

o  D.

byte b1 = 10; byte b=++b1;

正确答案:D

10.

(单选)运行下面的语句: String s=""; if(s==s+0){ System.out.println("Hello World"); } 编译,运行的结果是:()。

o  A.

Hello World

o  B.

无输出

o  C.

编译错误

o  D.

抛出运行时异常

正确答案:C

11.

(单选)下列代码编译和运行的结果是: public static void main(String[] args) { String[] elements = { "for", "tea", "too" }; String first = (elements.length > 0) ? elements[0] : null; System.out.println(first); }

o  A.

编译出错

o  B.

输出:tea

o  C.

输出:for

o  D.

输出:null

正确答案:C

12.

(单选)下列表达式中,可以得到精确结果的是()。

o  A.

double d1 = 3.0 - 2.6;

o  B.

double d4 = 2.5 * 1.5;

o  C.

double d2 = 30/300;

o  D.

double d3 = 1/2 + 0.5;

正确答案:B

13.

(单选)下列关于JVM说法,错误的是()。

o  A.

JVM通过专门的线程实现内存的回收。

o  B.

使用java命令时,可以通过参数来设置分配JVM的内存大小。

o  C.

JRE包括JVMJava核心类库。

o  D.

目前主流版本JVM通过纯解释的方式运行Java字节码。

正确答案:D

14.

(单选)请看下列代码: interface Data { public void load(); } abstract class Info { public abstract void load(); } 下列选项中,能正确使用Data接口和Info类的是()。

o  A.

public class Employee extends Info implements Data { public void load() { /*do something*/ } }

o  B.

public class Employee implements Info extends Data { public void load() { /*do something*/ } }

o  C.

public class Employee implements Info extends Data { public void Data.load() { /*d something */ } public void load() { /*do something */ } }

o  D.

public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }

正确答案:D

15.

(单选)下列数组声明语句中,错误的是:()。

o  A.

int[] arr = new int[8];

o  B.

int[] arr = new int[8]{};

o  C.

int[] arr = {};

o  D.

int[] arr = new int[]{};

正确答案:B

16.

(单选)运行下列代码: int[] oneArr = { 2, 11, 26, 27, 37, 44, 48, 60 }; int[] twoArr = { 19, 35, 49, 55, 58, 75, 83, 84, 91, 93 }; int[] threeArr = new int[oneArr.length + twoArr.length]; int p = 0, q = 0; while (p < oneArr.length && q < twoArr.length) { threeArr[p + q] = oneArr[p] < twoArr[q] ? oneArr[p++] : twoArr[q++]; } if (p < oneArr.length) { System.arraycopy(oneArr, p, threeArr, p + q, oneArr.length - p); } else if (q < twoArr.length) { System.arraycopy(twoArr, q, threeArr, p + q, twoArr.length - q); } System.out.println(s.toString(threeArr)); 输出的结果是:()。

o  A.

[2,11,26,27,37,44,48,60,19,35,49,55,58,75,83,84,91,93];

o  B.

[2,11,19,26,27,35,37,44,48,49,55,58,60,75,83,84,91,93];

o  C.

[19,35,49,55,58,75,83,84,91,93,2,11,26,27,37,44,48,60];

o  D.

[2,19,11,35,26,49,27,55,37,58,44,75,48,83,60,84,91,93];

正确答案:C

17.

(单选)程序的执行结果是: public class Test { public static void main(String[] args){ String str1 = new String("abc"); String str2 = new String("abc"); String str3 = str1; if(str1.equals(str2)){ System.out.println("true"); }else{ System.out.println("false"); } if(str1==str3){ System.out.println("true"); }else{ System.out.println("false"); } } }

o  A.

true true

o  B.

true false

o  C.

false true

o  D.

false false

正确答案:A

18.

(单选)运行下面的程序: String[] fileNames = { "abc.txt", "bcd.exe", "cde.exe", "def.dat","efg.exe" }; for (String fileName : fileNames) { if (fileName.endsWith(".exe")) { System.out.print(fileName.substring(0, fileName .lastIndexOf(".exe"))+" "); } } 控制台的输出结果是:()。

o  A.

bcd. cde. efg.

o  B.

bc cd ef

o  C.

bcd.exe cde.exe efg.exe

o  D.

bcd cde efg

正确答案:D

19.

(单选)如下方法声明中,错误的是()。

o  A.

public void say() { System.out.print(Hi); }

o  B.

public void say() { System.out.print(Hi); return; }

o  C.

public int say() { System.out.print(Hi); return; }

o  D.

public int say() { System.out.print(Hi); return 0; }

正确答案:C

20.

(单选)数据类型intchardouble所占用内存字节数分别是:()。

o  A.

428

o  B.

224

o  C.

218

o  D.

444

正确答案:A

21.

(单选)关于String StringBuffer 下面说法正确的是()。

o  A.

String操作字符串不改变原有字符串的内容

o  B.

StringBuffer连接字符串速度没有String

o  C.

String可以使用append方法连接字符串

o  D.

StringBufferjava.util包中

正确答案:A

22.

(单选)运行下面的程序: int a = 100; int b = 200; a = a + b; b = a - b; a = a - b; System.out.println("a=" + a + ", b=" + b); 输出的结果是:()。

o  A.

a=100, b=300

o  B.

a=100, b=200

o  C.

a=200, b=100

o  D.

a=300, b=200

正确答案:B

23.

(单选)下列代码的输出结果是: public class Yikes { public static void go(Long n) { System.out.println("Long"); } public static void go(Short n) { System.out.println("Short"); } public static void go(int n) { System.out.println("int"); } public static void main(String[] args) { short y = 6; long z = 7; go(y); go(z); } }

o  A.

Long Long

o  B.

Short Long

o  C.

int Long

o  D.

int int

正确答案:C

24.

(单选)分析如下语句,说法错误的是()。

o  A.

break可用于跳出循环,当多层嵌套时,只用于跳出一层循环

o  B.

break即可以出现在循环语句中也可以出现在switch语句中

o  C.

continue可以用于跳出循环

o  D.

continue不能出现在switch语句中

正确答案:C

25.

(单选)A类中有一个方法:protected int print(String str){},B类继承A类, 以下方法能在B类中重写A类中print()方法的是: ()。

o  A.

public int print(String str){}

o  B.

private int print(String str){}

o  C.

private void print(String str){}

o  D.

public void print(String str){}

正确答案:A

26.

(单选)下列代码的运行结果是: String test = "Test A. Test B. Test C."; String regex = "\\.\\s*"; String[] result = test.split(regex); for (String s : result) System.out.print(s + " ");

o  A.

Test A Test B Test C

o  B.

Test A. Test B. Test C.

o  C.

Test . Test . Test .

o  D.

A. B. C.

正确答案:A

27.

(单选)请看下列代码 public class Member{ private Long userId; private String nickName; //以下是gettersett方法 …… } Main方法中的代码: Member m1=new Member(); m1.setUserId(new Long(100001)); m1.setNickName("mick"); Member m2=new Member(); m2.setUserId(new Long(100001)); m2.setNickName("mick"); System.out.println(m1==m2); System.out.println(m1.equals(m2)); 控制台的输出结果是:

o  A.

true false

o  B.

false true

o  C.

false false

o  D.

true ture

正确答案:C

28.

(单选)实现Point类的equals方法,具体逻辑为:“成员变量xy分别相等的Point对象被视为相等”。 public class Point { private int x; private int y; ... public boolean equals(Object obj) { 《填入代码》 } } 《插入代码》处应填入的代码正确的是:

o  A.

if(obj.x == this.x || obj.y == this.y){ return true; } return false;

o  B.

if(obj.x == this.x && obj.y == this.y){ return true; } return false;

o  C.

if(!(obj instanceof Point)) return false; if(((Point)obj).x == ((Point)obj).y && this.x == this.y){ return true; } return false;

o  D.

if(!(obj instanceof Point)) return false; if(((Point)obj).x == this.x && ((Point)obj).y == this.y){ return true; } return false;

正确答案:D

29.

(单选)运行下列代码,输出为false的是:()。

o  A.

String st1 = "abc"; System.out.println("abc" == st1);

o  B.

String st2 = "abc"; System.out.println(st2.equals(new String("abc")));

o  C.

Integer i = 100; System.out.println(100 == i);

o  D.

List list = new List(); System.out.println(list.contains(null));

正确答案:A

30.

(单选)请看下列代码,出现错误的行是:() public interface Cookie{ Cookie cookie=new Cart ("小面包","盼盼"); } public class Cart implements Cookie{ private String name; private String production; public Cart(String name,String production){ this.name=name; this.production=production; } public void smell(){ cookie =new Cart("蛋黄派","达利园"); } }

o  A.

2

o  B.

4

o  C.

11

o  D.

12

正确答案:D

31.

(单选)请看下列代码的输出结果是: public class Bootchy { int bootch; String snootch; public Bootchy() { this("snootchy"); System.out.print("first "); } public Bootchy(String snootch) { this(420, "snootchy"); System.out.print("second "); } public Bootchy(int bootch, String snootch) { this.bootch = bootch; this.snootch = snootch; System.out.print("third "); } public static void main(String[] args) { Bootchy b = new Bootchy(); System.out.print(b.snootch + " " + b.bootch); } }

o  A.

first second third snootchy 420

o  B.

third second first snootchy 420

o  C.

third first second snootchy 420

o  D.

first second first third snootchy 420

正确答案:B

32.

(单选)下列语句创建对象的总个数是:()。 String s=a+b+c+d+e;

o  A.

1

o  B.

2

o  C.

3

o  D.

4

正确答案:A

33.

(单选)下面的代码用于对数组arr实现冒泡排序: for (int i = 0; i < arr.length - 1; i++) { boolean isSwap = false; 空白处 if (!isSwap) break; } 下列选项中,空白处可以填入的代码是:()。

o  A.

for (int j = arr.length - 1; j > i; j--) { if (arr[j] < arr[j - 1]) { int temp = arr[j]; arr[j] = arr[j - 1]; arr[j - 1] = temp; isSwap = true; } }

o  B.

for (int j = arr.length - 1; j > 0; j--) { if (arr[j] < arr[j - 1]) { int temp = arr[j]; arr[j] = arr[j - 1]; arr[j - 1] = temp; isSwap = true; } }

o  C.

for (int j = i + 1; j< arr.length; j++) { if (arr[j] < arr[j - 1]) { int temp = arr[j]; arr[j] = arr[j - 1]; arr[j - 1] = temp; isSwap = true; } }

o  D.

for (int j = i; j< arr.length; j++) { if (arr[j] < arr[j - 1]) { int temp = arr[j]; arr[j] = arr[j - 1]; arr[j - 1] = temp; isSwap = true; } }

正确答案:C

34.

(单选)请看下列代码: class Payload { private int weight; public Payload(int wt) { weight = wt; } public Payload() {} public void setWeight(int w) { weight = w; } public String toString() { return Integer.toString(weight); } } public class TestPayload { static void changePayload(Payload p) { <插入代码> } public static void main(String[] args) { Payload p = new Payload(); p.setWeight(1024); changePayload(p); System.out.println("The value of p is " + p); } } 假设运行后输出“The value of p is 420”,那么<插入代码>处应填入代码是:

o  A.

p.setWeight(420);

o  B.

Payload.setWeight(420);

o  C.

p = new Payload(420);

o  D.

p = new Payload(); p.setWeight(420);

正确答案:D

35.

(单选)下列代码运行的结果是()。 public class Base { public static final String FOO = "foo"; public static void main(String[] args) { Base b = new Base(); Sub s = new Sub(); System.out.print(Base.FOO); System.out.print(Sub.FOO); System.out.print(b.FOO); System.out.print(s.FOO); System.out.print(((Base) s).FOO); } } class Sub extends Base { public static final String FOO = "bar"; }

o  A.

foofoofoofoofoo

o  B.

foobarfoobarbar

o  C.

foobarfoofoofoo

o  D.

foobarfoobarfoo

正确答案:C

36.

(多选)请看下列代码: public abstract class Shape { int x; int y; public abstract void draw(); public void setAnchor(int x, int y) { this.x = x; this.y = y; } } 下列选项中能正确使用Shape类的是:

o  A.

public class Circle implements Shape { private int radius; }

o  B.

public abstract class Circle extends Shape { private int radius; }

o  C.

public class Circle extends Shape { private int radius; public void draw(); }

o  D.

public class Circle extends Shape { private int radius; public void draw() {/* code here */} }

正确答案:BCD

37.

(多选)Java语言中,下列说法正确的是()。

o  A.

一个接口可以继承多个接口

o  B.

一个类可以继承多个类

o  C.

一个类可以实现多个接口

o  D.

一个类可以有多个子类

正确答案:ACD

38.

(多选)请看下列代码: package com.tarena; public class Geodetics { public static final double DIAMETER = 12756.32; } 访问静态常量DIAMETER的方式正确的是:

o  A.

import com.tarena.Geodetics; public class TerraCarta { public double halfway(){ return Geodetics.DIAMETER/2.0; } }

o  B.

import com.tarena.Geodetics; public class TerraCarta { public double halfway(){ return DIAMETER/2.0; } }

o  C.

import com.tarena; public class TerraCarta { public double halfway(){ return Geodetics.DIAMETER/2.0; } }

o  D.

import com.tarena.*; public class TerraCarta { public double halfway(){ return Geodetics.DIAMETER/2.0; } }

正确答案:AD

39.

(多选)请看下列代码 public class Foo { public void method(String str,int age){} } Foo类中method方法重载的方法是:

o  A.

public int method(String str,int age){}

o  B.

public void method(String s,int year){}

o  C.

public void method(int year,String s){}

o  D.

public int method(int year,String s){}

正确答案:ACD

40.

(多选)<插入代码>处,填入下列代码编译正确的是: public void foo(int[] x) { <插入代码> }

o  A.

foreach(int z : x) System.out.println(z);

o  B.

for(int z : x) System.out.println(z);

o  C.

while( x.hasNext()) System.out.println( x.next());

o  D.

for( int i=0; i< x.length; i++ ) System.out.println(x[i]);

正确答案:BD

41.

(多选)查看如下代码: class A { protected int method (int a, int b) { return 0; } 下列选项中,可以在 A 的子类中使用的是()。

o  A.

public int method (int a, int b) { return 0; }

o  B.

private int method(int a, int b) { return 0; }

o  C.

private int method(int a, long b) { return 0; }

o  D.

public short method(int a, int b) { return 0; }

正确答案:AC

42.

(多选)题目代码的功能为:输出每个字符在一个字符串中出现的次数(不区分大小写) String str = "ewrwqFrewqfsadfdsfdsfs"; str=str.toLowerCase(); int max_length = 0; while (str.length() > 0) { 《插入代码》 }

o  A.

int length = str.length(); char first=str.charAt(0); String strNew = str.replaceAll(String.valueOf(first), ""); if (length>strNew.length()) { max_length = length - strNew.length(); System.out.println(first+":"+max_length); }

o  B.

int length = str.length(); char first=str.charAt(0); String strNew = str.replaceAll(String.valueOf(first), ""); if (length>strNew.length()) { max_length = length - strNew.length(); str = strNew; System.out.println(first+":"+max_length); }

o  C.

int length = str.length(); String first = str.substring(0, 1); String strNew = str.replaceAll(first, ""); if (length>strNew.length()) { max_length = length - strNew.length(); str = strNew; System.out.println(first+":"+max_length); }

o  D.

int length = str.length(); String first = str.substring(0, 1); String strNew = str.replaceAll(first, ""); if (length>strNew.length()) { max_length = length - strNew.length(); System.out.println(first+":"+max_length); }

正确答案:BC

43.

(多选)Java语言中,下列说法正确的是:()。

o  A.

StringBufferStringBuilder的区别在于:StringBuffer是线程安全的而StringBuilder不是。

o  B.

String是不可变对象,而StringBuffer中封装的字符串数据是可以动态改变的。

o  C.

判断两个StringBuilder对象的字符序列是否相同,可以调用其equlas方法进行比较。

o  D.

String的重写了equals方法,重写的逻辑是:字符序列相同的String对象equals方法返回true

正确答案:ABD

44.

(多选)下面的方法属于StringBuffer的是:()。

o  A.

size

o  B.

insert

o  C.

delete

o  D.

length

正确答案:BCD

45.

(多选)请看下列代码: public class Old { public static Object get(List list) { return list.get(0); } } 以下选项调用get方法,能编译通过的是:

o  A.

Object o = Old.get(new LinkedList());

o  B.

Object o = Old.get(new LinkedList());

o  C.

String s = Old.get(new LinkedList());

o  D.

String s = (String)Old.get(new LinkedList());

正确答案:ABD

46.

(多选)查看如下代码: public class Foo { public void method(String str,int age){} } 下列选项中,和 Foo 类中 method 方法重载的方法是()。

o  A.

public int method(String str,int age){}

o  B.

public void method(int year,String s){}

o  C.

public int method(int year,String s){}

o  D.

public int method(String str){}

正确答案:BCD

47.

(多选)请看下列代码: class One { public One foo() { return this; } } class Two extends One { public One foo() { return this; } } class Three extends Two { <插入代码> } 下列选项中的代码,放置在<插入代码>处无编译错误的是:

o  A.

public void foo() { }

o  B.

public Object foo() { return this; }

o  C.

public Two foo() { return this; }

o  D.

public One foo() { return this; }

正确答案:ACD

48.

(多选)所谓“水仙花”数是一个整数等于各位数字立方的和,例如:153 = 1*1*1+5*5*5+3*3*3,下面的程序用于输出2~1000内的水仙花数: for (int n = 2; n <= 1000; n++) { 空白处 if (s == n) { System.out.println(n); } } 下列选项中,空白处可以填入的代码是:()。

o  A.

int s = 0, n1 = n; while (n1 > 0) { int t = n1 % 10; s += t * t * t; n1 /= 10; }

o  B.

int s = 0, n1 = n; while (n1 > 0) { int t = n1 / 10; s+= t * t * t; n1 %= 10; }

o  C.

int s = 0; for(int n1 = n; n1>0; n1 /= 10) { int t = n1%10; s += t * t * t; }

o  D.

int s = 0; for(int n1 = n; n1>0; n1 %= 10) { int t = n1 / 10; s += t * t * t; }

正确答案:AC

49.

(多选)下列赋值语句中,会有编译错误的是()。

o  A.

int a = 8888888888;

o  B.

char b = 1000+300;

o  C.

byte c = 100+30;

o  D.

int d = 'a'+'b'+'c';

正确答案:AC

50.

(多选)下列逻辑表达式,值为false的是()。

o  A.

"abc,,,bcd,,def,efg,,".split("[,]+").length == 4;

o  B.

"1st456".matches("\\d[a-z&&[^et]]{2,8}[0-9]+");

o  C.

"abcdefghijklmnopqrstuvwxyz".substring(5,26).length() == 20;

o  D.

"whatisjava".equals(null);

正确答案:BCD

关于我们 | 服务支持 | 咨询与反馈 | 最新动态 | 代理合作 | 名师堂

达内时代科技集团有限公司 2013-2014

中关村中心企业合作:62117598 UID中心企业合作:8216842182168831

达内java2015.11第一次月考(附答案).doc

相关推荐