达内第一次月考试题 15年
在线考试 本次考试得分:96.0
1.
(单选题)下列代码的运行结果是: 01 public class GoTest {
02 public static void main(String[] args) { 03 Sente a = new Sente(); 04 a.go();
05 Goban b = new Goban(); 06 b.go();
07 Stone c = new Stone(); 08 c.go(); 09 } 10 }
11 class Sente implements Go { 12 public void go() {
13 System.out.println("go in Sente"); 14 } 15 }
16 class Goban extends Sente { 17 public void go() {
18 System.out.println("go in Goban"); 19 } 20 }
21 class Stone extends Goban implements Go { 22 }
23 interface Go { 24 public void go(); 25 }
o A.
go in Goban go in Sente go in Sente
o
B.
go in Sente go in Sente go in Goban
o
C.
go in Sente go in Goban go in Goban
o
D.
go in Goban go in Goban go in Sente
正确答案:C解析:
2.
(单选题)请看下列代码: 01 class Payload { 02 private int weight; 03 public Payload(int wt) { 04 weight = wt; 05 }
06 public Payload() {}
07 public void setWeight(int w) { 08 weight = w; 09 }
10 public String toString() {
11 return Integer.toString(weight); 12 } 13 }
14 public class TestPayload {
15 static void changePayload(Payload p) { 16 17 }
18 public static void main(String[] args) { 19 Payload p = new Payload(); 20 p.setWeight(1024); 21 changePayload(p);
22 System.out.println("The value of p is " + p);
23 } 24 }
假设运行后输出“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);
正确答案:A解析:
3.
(单选题)关于下列代码说法不正确的是: 01 10. interface Foo { 02 11. int bar(); 03 12. } 04 13.
05 14. public class Beta { 06 15.
07 16. class A implements Foo { 08 17. public int bar() { return 1; } 09 18. } 10 19.
11 20. public int fubar( Foo foo) { return foo.bar(); } 12 21.
13 22. public void testFoo() { 14 23.
15 24. class A implements Foo { 16 25. public int bar() { return 2; } 17 26. } 18 27.
19 28. System.out.println( fubar( new A()));
20 29. } 21 30.
22 31. public static void main( String[] argv) { 23 32. new Beta().testFoo(); 24 33. } 25 34. }
o
A.
编译错误
o
B.
运行代码输出:2
o
C.
如果删除16,17,18行,运行代码应然输出:2
o
D.
如果删除24,25,26行,运行代码输出:1
正确答案:A解析:
∙ 4.
(单选题)分析如下语句,说法错误的是()。
o
A.
break可用于跳出循环,当多层嵌套时,只用于跳出一层循环
o
B.
break即可以出现在循环语句中也可以出现在switch语句中
o
C.
continue可以用于跳出循环
o
D.
continue不能出现在switch语句中
正确答案:C解析:
∙ 5.
(单选题)在Java语言中,下列说法正确的是:()。
o
A.
Java访问修饰符按照访问范围由低到高的排列顺序是public,default,protected,private
o
B.
private可以用于外部类的声明
o
C.
一个Java源文件中声明为public的外部类只能有一个
o
D.
protected声明的方法不可以被子类重写
正确答案:C解析:
6.
(单选题)下列代码的输出结果是: 01 class Cup { 02 }
03 class PoisonCup extends Cup { 04 public void takeCup(Cup c) { 05 if (c instanceof PoisonCup) { 06 System.out.println("Inconceivable!"); 07 } else if (c instanceof Cup) {
08 System.out.println("Dizzying intellect!"); 09 } else { 10 System.exit(0); 11 } 12 } 13 }
14 public class TestCup {
15 public static void main(String[] args) { 16 Cup cup = new PoisonCup(); 17 PoisonCup poison=new PoisonCup(); 18 poison.takeCup(cup); 19 } 20 }
o
A.
Inconceivable!
o B.
Dizzying intellect!
o
C.
代码正常运行,但是无输出
o
D.
抛出运行时异常
正确答案:A解析:
7.
(单选题)请看下列代码编译和运行的结果是: 01 package packagea; 02 public class Message { 03 String getText() { 04 return "text"; 05 } 06 }
07 package packageb;
08 public class XMLMessage extends packagea.Message{ 09 String getText() { 10 return "
11 12 text 13 "; 14 }
15 public static void main(String[] args) { 16 System.out.println(new XMLMessage().getText()); 17 } 18 }
o
A.
text
o
B.
text
o
C.
抛出运行时异常
o
D.
代码public class XMLMessage extends packagea.Message{行,编译错误
正确答案:B解析:
∙ 8.
(单选题)下列属于不合法Java标识符的是()。
o
A.
_avaj
o
B.
5save
o
C.
Avaj
o
D.
$80
正确答案:B解析:
∙ 9.
(单选题)编译和运行以下代码的结果为()。 1 public class MyMain{
2 public static void main(String argv){ 3 System.out.println("Hello cruel world"); 4 } 5 }
o
A.
编译错误
o
B.
运行输出 "Hello cruel world"
o
C.
编译无错,但运行时指示没有定义构造方法
o
D.
编译无错,但运行时指示没有正确定义main方法
正确答案:D解析:
∙ 10.
(单选题)下列代码编译和运行的结果是: 01 public class Wow { 02 public static void go(short n) { 03 System.out.println("short"); 04 }
05 public static void go(Short n) { 06 System.out.println("SHORT"); 07 }
08 public static void go(Long n) { 09 System.out.println(" LONG"); 10 }
11 public static void main(String[] args) { 12 Short y = 6; 13 int z = 7; 14 go(y); 15 go(z); 16 } 17 }
o
A.
short LONG
o
B.
SHORT LONG
o
C.
编译失败
o
D.
抛出运行时异常
正确答案:C解析:
∙ 11.
(单选题)在Java语言中,字符串“Java程序员”在内存中所占用的字节数是:()。
o
A.
10
o
B.
7
o
C.
13
o
D.
14
正确答案:D解析:
∙ 12.
(单选题)List类的对象list中的元素为:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],现在想返回该list对象的子集合[5,6,7,8], 需要做的操作是:
o
A.
list.subList(5, 8);
o
B.
list.subList(5, 9);
o
C.
list.subList(4, 8);
o
D.
list.subList(4, 9);
正确答案:B解析:
∙ 13.
(单选题)请看下列代码: 1 public static void main(String[] args) { 2 Calendar c = Calendar.getInstance(); 3 c.set(Calendar.YEAR, 2013);
4 c.set(Calendar.MONTH, Calendar.FEBRUARY);
5 c.set(Calendar.DATE, 28); 6 7 }
在处填入将Calendar表示的日期转换为Date表示的日期:
o
A.
Date d=c.getDate();
o
B.
Date d=c.getCalendar();
o
C.
Date d=c.getNow();
o
D.
Date d=c.getTime();
正确答案:D解析:
∙ 14.
(单选题)Java语言可以跨平台的原因是:
o
A.
Java面向对象
o
B.
Java虚拟机
o
C.
Java垃圾回收机制
o
D.
Java编译器
正确答案:B解析:
∙ 15.
(单选题)请看下列程序的输出结果是: 01 public class Item { 02 private String desc;
03 public String getDescription() { 04 return desc;
05 }
06 public void setDescription(String d) { 07 desc = d; 08 }
09 public static void modifyDesc(Item item, String desc) { 10 item = new Item(); 11 item.setDescription(desc); 12 }
13 public static void main(String[] args) { 14 Item it = new Item();
15 it.setDescription("Gobstopper"); 16 Item it2 = new Item();
17 it2.setDescription("Fizzylifting"); 18 modifyDesc(it, "Scrumdiddlyumptious"); 19 System.out.println(it.getDescription()); 20 System.out.println(it2.getDescription()); 21 } 22 }
o
A.
Scrumdiddlyumptious Scrumdiddlyumptious
o
B.
Scrumdiddlyumptious Fizzylifltng
o
C.
Gobstopper Scrumdiddlyumptious
o
D.
Gobstopper Fizzylifting
正确答案:D解析:
16.
(单选题)请看下列代码: 01 class ClassA {}
02 class ClassB extends ClassA {} 03 class ClassC extends ClassA {} 04 public class Test{
05 public static void main(String[] args) { 06 ClassA p0 = new ClassA(); 07 ClassB p1 = new ClassB(); 08 ClassC p2 = new ClassC(); 09 ClassA p3 = new ClassB(); 10 ClassA p4 = new ClassC(); 11 12 } 13 }
可以在处,填入的代码正确的是()
o
A.
p0 = p1;
o
B.
p1 =p2;
o
C.
p2 = p4;
o
D.
p2 = (ClassC)p1;
正确答案:A解析:
17.
(单选题)下列代码编译和运行的结果是() public class Foo { public static void main(String[] args) { java.util.List list = new
java.util.ArrayList(); list.add(new B()); list.add(new C()); for (A a : list) { a.x(); a.y(); } } } interface A { void x(); } class B implements A { public void x() {} public void y() {} } class C extends B { public void x() {} }
o
A.
代码运行没有输出
o
B.
运行时抛出异常
o C.
代码a.y();行,编译错误
o
D.
代码java.util.List list = new java.util.ArrayList();行,编译错误
正确答案:C解析:
∙ 18.
(单选题)请看下列代码: 1 public static void main(String[] args) { 2
3 System.out.println(s); 4 }
如果程序输出的结果是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.substring(3,6).delete( 1 ,3).insert( 1, "24");
o
D.
StringBuilder s = new StringBuilder("123456789"); s.substring(3,6).delete( 1 ,2).insert( 1, "24");
正确答案:B解析:
∙ 19.
(单选题)下列代码的运行结果是()。 01 public class Animal { 02 public String noise() { 03 return "peep"; 04 }
05 public static void main(String[] args) { 06 Animal animal = new Dog(); 07 Cat cat = (Cat)animal;
08 System.out.println(cat.noise()); 09 } 10 }
11 class Dog extends Animal { 12 public String noise() { 13 return "bark"; 14 } 15 }
16 class Cat extends Animal { 17 public String noise() { 18 return "meow"; 19 } 20 }
o
A.
peep
o
B.
bark
o
C.
meow
o
D.
抛出运行时异常
正确答案:D解析:
20.
(单选题)下列代码编译和运行的结果是()。 01 public class A { 02 public void start() {
03 System.out.println("TestA"); 04 } 05 }
06 public class B extends A {
07 public void start() {
08 System.out.println("TestB"); 09 }
10 public static void main(String[] args) { 11 ((A) new B()).start(); 12 } 13 }
o
A.
输出:TestA
o
B.
输出:TestB
o
C.
输出:TestA TestB
o
D.
编译错误
正确答案:B解析:
∙ 21.
(单选题)下列Java标识符,错误的是()
o
A.
_sys_varl
o
B.
$change
o
C.
User_name
o
D.
1_file
正确答案:D解析:
∙ 22.
(单选题)下面的代码用于对数组arr实现冒泡排序: 1 for (int i = 0; i
2 boolean isSwap = false; 3 空白处 4 if (!isSwap) 5 break; 6 }
下列选项中,空白处可以填入的代码是:()。
o
A.
for (int j = arr.length - 1; j > i; j--) { if (arr[j]
o
B.
for (int j = arr.length - 1; j > 0; j--) { if (arr[j]
o
C.
for (int j = i + 1; j
o
D.
for (int j = i; j
正确答案:A解析:
23.
(单选题)下面的程序可以输出1~100内前10个3的倍数: 1 for (int i = 1, count = 0; i
3 System.out.println(i); 4 (空白处) 5 } 6 }
下列选项中,空白处可以填入的代码是()。
o
A.
if (count++ >= 10) { break; }
o
B.
if (++count >= 10) { break; }
o C.
if (count++ >= 10) { continue; }
o
D.
if (++count >= 10) { continue; }
正确答案:B解析:
∙ 24.
(单选题)仔细分析下列代码,请指出错误的行()。 1 public class SomeThing{ 2 private String str; 3 public int addOne(final int x){ 4 return ++x; 5 } 6 }
o
A.
public class SomeThing
o
B.
private String str;
o
C.
public int addOne(final int x)
o
D.
return ++x;
正确答案:D解析:
∙ 25.
(单选题)下列属于不合法Java标识符的是()。
o
A.
_mem
o
B.
12a
o
C.
M12
o
D.
$12
正确答案:B解析:
∙ 26.
(单选题)下面不属于Java语言特点的是:
o
A.
平台无关
o
B.
面向对象
o
C.
支持指针类型
o
D.
垃圾回收机制
正确答案:C解析:
∙ 27.
(单选题)下列代码运行的结果是()。 01 public class Base {
02 public static final String FOO = "foo"; 03 public static void main(String[] args) { 04 Base b = new Base(); 05 Sub s = new Sub(); 06 System.out.print(Base.FOO); 07 System.out.print(Sub.FOO); 08 System.out.print(b.FOO); 09 System.out.print(s.FOO);
10 System.out.print(((Base) s).FOO); 11 } 12 }
13 class Sub extends Base {
14 public static final String FOO = "bar";
15 }
o
A.
foofoofoofoofoo
o
B.
foobarfoobarbar
o
C.
foobarfoofoofoo
o
D.
foobarfoobarfoo
正确答案:D解析:
∙ 28.
(单选题)下列表达式中,可以得到精确结果的是()。
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解析:
∙ 29.
(单选题)请看下列代码: 01 interface Foo { 02 int bar(); 03 }
04 public class Sprite { 05 public int fubar(Foo foo) { 06 return foo.bar(); 07 }
08 public void testFoo() { 09 fubar( 10 11 ); 12 } 13 }
使类Sprite编译通过,在处应填入的代码是:
o
A.
Foo { public int bar() { return 1; } }
o
B.
new Foo { public int bar() { return 1; } }
o
C.
new Foo() { public int bar(){return 1; } }
o
D.
new class Foo { public int bar() { return 1; } }
正确答案:C解析:
30.
(单选题)关于下列代码说法正确的是: 01 class ClassA { 02 public int numberOfinstances;
03 protected ClassA(int numberOfinstances) { 04 this.numberOfinstances = numberOfinstances; 05 } 06 }
07 public class ExtendedA extends ClassA { 08 private ExtendedA(int numberOfinstances) { 09 super(numberOfinstances); 10 }
11 public static void main(String[] args) { 12 ExtendedA ext = new ExtendedA(420); 13 System.out.print(ext.numberOfinstances); 14 }
15 }
o
A.
运行后,输出420
o
B.
运行时抛出异常
o
C.
编译错误,所有的构造器必须是public的
o
D.
编译错误,构造器不能是private的
正确答案:A解析:
∙ 31.
(单选题)下列数组声明语句中,错误的是:()。
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解析:
∙ 32.
(单选题)运行下面的语句: 1 String s=""; 2 if(s==s+0){
3 System.out.println("Hello World"); 4 }
编译,运行的结果是:()。
o
A.
Hello World
o
B.
无输出
o
C.
编译错误
o
D.
抛出运行时异常
正确答案:B解析:
∙ 33.
(单选题)下列赋值语句中,正确的是()。
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解析:
∙ 34.
(单选题)数据类型int、char和double所占用内存字节数分别是:()。
o
A.
4、2和8
o
B.
2、2和4
o
C.
2、1和8
o
D.
4、4和4
正确答案:A解析:
∙ 35.
(单选题)请看下列代码: public class Test { public static void main(String[] args) { List strings = new ArrayList(); } } 下列选择中放在第5行编译失败的是:
o
A.
String s = strings.get(0);
o
B.
Iterator i1 = strings.iterator();
o
C.
String[] array1 = strings.toArray();
o
D.
Iterator i2 = strings.iterator();
正确答案:C解析:
∙ 36.
(多选题)下列赋值语句中,会有编译错误的是()。
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解析:
∙ 37.
(多选题)请看下列代码: 1 public class Old {
2 public static Object get(List list) { 3 return list.get(0); 4 } 5 }
以下选项调用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());
正确答案:AD解析:
∙ 38.
(
多选题)在处,填入下列代码编译正确的是: 1 public void foo(int[] x) { 2 3 }
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
正确答案:BD解析:
∙ 39.
(多选题)请看下列代码:
1 public abstract class Shape { 2 int x; 3 int y;
4 public abstract void draw();
5 public void setAnchor(int x, int y) { 6 this.x = x; 7 this.y = y; 8 } 9 }
下列选项中能正确使用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 */} }
正确答案:BD解析:
40.
(多选题)请看下列代码: 01 class One { 02 public One foo() { 03 return this; 04 } 05 }
06 class Two extends One { 07 public One foo() { 08 return this; 09 } 10 }
11 class Three extends Two { 12 13 }
下列选项中的代码,放置在处无编译错误的是:
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; }
正确答案:CD解析:
41.
(多选题)所谓“水仙花”数是一个整数等于各位数字立方的和,例如:153 = 1*1*1+5*5*5+3*3*3, 下面的程序用于输出2~1000内的水仙花数:
1 for (int n = 2; n
空白处 3 if (s == n) {
4 System.out.println(n); 5 } 6 }
下列选项中,空白处可以填入的代码是:()。
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解析:
∙ 42.
(多选题)在
Java语言中,下列说法正确的是:()。
o
A.
StringBuffer和StringBuilder的区别在于:StringBuffer是线程安全的而StringBuilder不是。
o
B.
String是不可变对象,而StringBuffer中封装的字符串数据是可以动态改变的。
o
C.
判断两个StringBuilder对象的字符序列是否相同,可以调用其equlas方法进行比较。
o
D.
String的重写了equals方法,重写的逻辑是:字符序列相同的String对象equals方法返回true。
正确答案:ABD解析:
∙ 43.
(多选题)请看下列代码 1 public class Foo {
2 public void method(String str,int age){} 3 }
和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){}
正确答案:CD解析:
∙ 44.
(多选题)请看下列代码: 1 public class Key { 2 private
long id1; 3 private long 1d2; 4 // class Key methods 5 }
程序员开发Key类,作为java.util.HashMap的key,那么Key应该覆盖的两个方法是:
o
A.
public int hashCode()
o
B.
public boolean equals(Key k)
o
C.
public int compareTo(Object o)
o
D.
public boolean equals(Object o)
正确答案:AD解析:
∙ 45.
(多选题)在Java语言中,下列说法正确的是()。
o
A.
一个接口可以继承多个接口
o
B.
一个类可以继承多个类
o C.
一个类可以实现多个接口
o
D.
一个类可以有多个子类
正确答案:ACD解析:
∙ 46.
(多选题)查看如下代码: 1 class A {
2 protected int method (int a, int b) {
3 return 0; 4
} 5 }
下列选项中,可以在 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解析:
∙ 47.
(多选题)请看下列代码: Map map=new
HashMap(); map.put("one",100); map.put("two",200); map.put("three",300); 遍历map对象中的每一个元素,下列选项正确的是:
o
A.
Set set=map.keySet(); for(String key:set){ Integer value=map.get(key); System.out.println(key+”:”+value); }
o B.
List list=map.keyList(); for(String key:list){ Integer value=map.getKey(key); System.out.println(key+”:”+value); }
o
C.
Set> set = map.entrySet(); for (Map.Entry per : set) { System.out.println(per.getKey() + ":" + per.getValue()); }
o
D.
List list=map.entryList(); for(Entry
per:list){ System.out.println(per.getKey() + ":" + per.getValue()); }
正确答案:AC解析:
∙ 48.
(多选题)下列关于HashMap的描述正确的是:
o
A.
HashMap的Key和Value是以链表的方式存入对应的bucket
o
B.
HashMap的查找方式是获取Key的hashCode值,通过hash算法确定存储的bucket,调用equals方法依次与bucket中的Key进行比较
o
C.
放入HashMap集合中的元素按照key的自然顺序排序
o
D.
HashMap中的key是不可以的重复的
正确答案:ABD解析:
∙ 49.
(多选题)下面的方法属于StringBuffer的是:()。
o
A.
size
o
B.
insert
o C.
delete
o D.
length
正确答案:BCD解析:
50.
(多选题)题目代码的功能为:输出每个字符在一个字符串中出现的次数(不区分大小写)。
1 String str = "ewrwqFrewqfsadfdsfdsfs";
2 str=str.toLowerCase();
3 int max_length = 0;
4 while (str.length() > 0) {
5 《插入代码》
6 }
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解析:
关于我们 | 服务支持 | 咨询与反馈 | 最新动态 | 代理合作 | 名师堂 达内时代科技集团有限公司 2013-2014
中关村中心企业合作:62117598 UID中心企业合作:82168421、82168831