JAVA笔试题

C:\Users\Administrator.C-20150718ZKWUA\AppData

在线考试 本次考试得分:92.0
1.
(单选题)分析如下语句,说法错误的是()。
A.break可用于跳出循环,当多层嵌套时,只用于跳出一层循环
B.break即可以出现在循环语句中也可以出现在switch语句中
C.continue可以用于跳出循环
D.continue不能出现在switch语句中
正确答案:C解析:
2.
(单选题)请看下列代码:
1
public String makinStrings() {
2
String s = "Fred";
3
s = s + "47";
4
s = s.substring(2, 5);
5
s = s.toUpperCase();
6
return s.toString();
7
}
调用makinString方法,得到的字符串长度是:
A.1
B.2
C.3
D.4
正确答案:C解析:
3.
(单选题)下列选项中的类,能正确实现https://www.360docs.net/doc/da10777418.html,ng.Runnable接口和https://www.360docs.net/doc/da10777418.html,ng.Clonable接口的是()。
A.
1
public class Session implements Runnable, Clonable {
2
public void run();
3
public Object clone();
4
}
B.
1
public class Session implements Runnable, implements Clonable {
2
public void run() { / do something */ }
3
public Object clone() { / make a copy */ }
4
}
C.
1
public class Session implements Runnable, Clonable {
2
public void run() { / do something */ }
3
public Object clone() { /* make a copy */ }
4
}
D.
1
public class Session extends Runnable, Clonable {
2
public void run() ;
3
public Object clone();
4
}
正确答案:C解析:
4.
(单选题)下面的程序可以输出1~100内前10个3的倍数:
1
for (int i = 1, count = 0; i < 100; i++) {
2
if (i % 3 == 0) {
3
System.out.println(i);
4
(空白处)
5
}
6
}
下列选项中,空白处可以填入的代码是()。
A.
1
if (count++ >= 10) {
2
break;
3
}
B.
1
if (++count >= 10) {
2
break;
3
}
C.
1
if (count++ >= 10) {
2
continue;
3
}
D.
1
if (++count >= 10) {
2
continue;
3
}
正确答案:B解析:
5.
(单选题)下列代码编译和运行的结果是() 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() {} }
A.代码运行没有输出
B.运行时抛出异常
C.代码a.y();行,编译错误
D.代码java.util.List
list = new java.util.ArrayList();行,编译错误
正确答案:C解析:
6.
(单选题)仔细分析下列代码,请指出错误的行()。
1
public class SomeThing{
2
private String str;
3
public int addOne(final int x){
4
return ++x;
5
}
6
}
A.public class SomeThing
B.private String str;
C.public int addOne(final int x)
D.return ++x;
正确答案:D解析:
7.
(单选题)Java语言中int

类型表示整数的最大范围是:
A.-2147483647 ~ 2147483647
B.-2147483648 ~ 2147483647
C.-32767~32767
D.-32768~32767
正确答案:B解析:
8.
(单选题)下列代码的输出结果是()。
1
public static void main(String[] args) {
2
int[] one=new int[]{4,6,8};
3
int[] two=new int[]{1,3,5,7,9};
4
System.arraycopy(one, 1, two, 2, 2); System.out.println(Arrays.toString(two));
5
}
A.[1, 3, 7, 4, 6]
B.[1, 3, 5, 7, 8]
C.[1, 3, 5, 6, 9]
D.[1, 3, 6, 8, 9]
正确答案:D解析:
9.
(单选题)关于下列代码说法正确的是:
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
}
A.运行后,输出420
B.运行时抛出异常
C.编译错误,所有的构造器必须是public的
D.编译错误,构造器不能是private的
正确答案:A解析:
10.
(单选题)下列Java标识符,错误的是()
A._sys_varl
B.$change
https://www.360docs.net/doc/da10777418.html,er_name
D.1_file
正确答案:D解析:
11.
(单选题)运行下面的语句:
1
String s="";
2
if(s==s+0){
3
System.out.println("Hello World");
4
}
编译,运行的结果是:()。
A.Hello World
B.无输出
C.编译错误
D.抛出运行时异常
正确答案:B解析:
12.
(单选题)下面关于数组的声明语句中,有编译错误的是:()。
A.int[] arr = new int[]{1,2,3};
B.int[] arr = null; arr = {1,2,3,4,5};
C.int[][] arr = new int[][]{{1,2,3},{4,5},{6}}
D.int[][] arr = new int[2][];
正确答案:B解析:
13.
(单选题)下列数组声明语句中,错误的是:()。
A.int[] arr = new int[]{};
B.int[] arr = new int[];
C.int[] arr = {};
D.int[][] arr = new int[2][]
正确答案:B解析:
14.
(单选题)下列代码编译和运行的结果是:
1
public static void main(String[] args) {
2
String[] elements = { "for", "tea", "too" };
3
String first = (elements.length > 0) ? elements[0] : null;
4
System.out.println(first);
5
}
A.编译出错
B.输出:tea
C.输出:for
D.输出:null
正确答案:C解析:
15.
(单选题)运行下面程序: public static void main(String[] args) { Map map=new HashMap(); map.put(String.valueOf(System.currentTimeMillis())+"a", "1"); map.put(String.valueOf(System.currentTimeMillis())+"b", "2"); map.put(String.valueOf(System.currentTimeMillis())+"c", "3"); for(Map.Entry entry:map.entrySet()){ System.out.println(entry.getValue()); } } 输出的结果是()
A.123
B.312
C.213
D.123顺序无法确定
正确答案:D解

析:
16.
(单选题)下列语句创建对象的总个数是:()。
1
String s=”a”+”b”+”c”+”d”+”e”;
A.1
B.2
C.3
D.4
正确答案:A解析:
17.
(单选题)下面的代码用于对数组arr实现冒泡排序:
1
for (int i = 0; i < arr.length - 1; i++) {
2
boolean isSwap = false;
3
空白处
4
if (!isSwap)
5
break;
6
}
下列选项中,空白处可以填入的代码是:()
A.
1
for (int j = arr.length - 1; j > i; j--) {
2
if (arr[j] < arr[j - 1]) {
3
int temp = arr[j];
4
arr[j] = arr[j - 1];
5
arr[j - 1] = temp;
6
isSwap = true;
7
}
8
}
B.
1
for (int j = arr.length - 1; j > 0; j--) {
2
if (arr[j] < arr[j - 1]) {
3
int temp = arr[j];
4
arr[j] = arr[j - 1];
5
arr[j - 1] = temp;
6
isSwap = true;
7
}
8
}
C.
1
for (int j = i + 1; j< arr.length; j++) {
2
if (arr[j] < arr[j - 1]) {
3
int temp = arr[j];
4
arr[j] = arr[j - 1];
5
arr[j - 1] = temp;
6
isSwap = true;
7
}
8
}
D.
1
for (int j = i; j< arr.length; j++) {
2
if (arr[j] < arr[j - 1]) {
3
int temp = arr[j];
4
arr[j] = arr[j - 1];
5
arr[j - 1] = temp;
6
isSwap = true;
7
}
8
}
正确答案:A解析:
18.
(单选题)下列代码运行的结果是()。
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
}
A.foofoofoofoofoo
B.foobarfoobarbar
C.foobarfoofoofoo
D.foobarfoobarfoo
正确答案:D解析:
19.
(单选题)请看下列代码:
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表示的日期:
A.Date d=c.getDate();
B.Date d=c.getCalendar();
C.Date d=c.getNow();
D.Date d=c.getTime();
正确答案:D解析:
20.
(单选题)下列程序的输出结果是()。
1
public static void main(String[] args) {
2
String str="ABCDEF";
3
String sub=str.substring(3,5);
4
System.out.println(sub);
5
}
A.CD
B.CDE
C.DE
D.DEF
正确答案:C解析:
21.
(单选题)下列代码的运行结果是()
1
public static void main(String[] args) {
2
String str = "420";
3
str += 42;
4
System.out.print(str);
5
}
A.42

B.420
C.462
D.42042
正确答案:D解析:
22.
(单选题)请看下列代码,出现错误的行是:()
01
public interface Cookie{
02
Cookie cookie=new Cart ("小面包","盼盼");
03
}
04
public class Cart implements Cookie{
05
private String name;
06
private String production;
07
public Cart(String name,String production){
08
https://www.360docs.net/doc/da10777418.html,=name;
09
this.production=production;
10
}
11
public void smell(){
12
cookie =new Cart("蛋黄派","达利园");
13
}
14
}
A.第2行
B.第4行
C.第11行
D.第12行
正确答案:D解析:
23.
(单选题)请看下列代码:
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
}
可以在<插入代码>处,填入的代码正确的是()
A.p0 = p1;
B.p1 =p2;
C.p2 = p4;
D.p2 = (ClassC)p1;
正确答案:A解析:
24.
(单选题)请看下列代码:
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”,那么<插入代码>处应填入代码是:
A.p.setWeight(420);
B.Payload.setWeight(420);
C.p = new Payload(420);
D.p = new Payload(); p.setWeight(420);
正确答案:A解析:
25.
(单选题)List类的对象list中的元素为:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],现在想返回该list对象的子集合[5,6,7,8] ,需要做的操作是:
A.list.subList(5, 8);
B.list.subList(5, 9);
C.list.subList(4, 8);
D.list.subList(4, 9);
正确答案:B解析:
26.
(单选题)关于下列代码说法正确的是:
01
public class A {
02
private int counter = 0;
03
public static int getInstanceCount() {
04
return counter;
05
}
06
public A() {
07
counter++;
08
}
09
public static void main(String[] args) {
10
A a1 = new A();
11
A a2 = new A();
12
A a3 = new A();
13
System.out.println(A.getInstanceCount());
14
}
15
}
A.该类编译失败
B.输出:1
C.输出:3
D.输出:0
正确答案:A解析:
27.
(

单选题)在Java语言中,下列说法正确的是:()。
A.Java访问修饰符按照访问范围由低到高的排列顺序是public,default,protected,private
B.private可以用于外部类的声明
C.一个Java源文件中声明为public的外部类只能有一个
D.protected声明的方法不可以被子类重写
正确答案:C解析:
28.
(单选题)下列代码的输出结果是()。
1
int j=0;
2
for(int i=0;i<100;i++){
3
j=j++;
4
}
5
System.out.println(j);
A.0
B.99
C.100
D.101
正确答案:A解析:
29.
(单选题)类A,B的定义如下:
01
class A {
02
private int a = 100;
03
A() {
04
System.out.print("A()");
05
System.out.println(a);
06
}
07
}
08
class B extends A {
09
private int a = 200;
10
B() {
11
System.out.print("B()");
12
System.out.println(a);
13
}
14
}
运行下面的代码: new B(); 输出的结果是:()。
A.
1
A() 100
2
B() 200
B.
1
A() 200
2
B() 200
C.
1
B() 200
2
A() 100
D.
1
B() 200
2
A() 200
正确答案:A解析:
30.
(单选题)关于下列代码说法正确的是:
01
public class Money {
02
private String country, name;
03
public String getCountry() {
04
return country;
05
}
06
}
07
class Yen extends Money {
08
public String getCountry() {
09
return super.country;
10
}
11
}
12
class Euro extends Money {
13
public String getCountry(String timeZone) {
14
return super.getCountry();
15
}
16
}
A.Yen类编译正确
B.Euro类编译正确
C.Money类编译错误
D.Yen和Money编译错误
正确答案:B解析:
31.
(单选题)下列代码的输出结果是: public static void main(String[] args) { Queue queue = new LinkedList(); queue.offer("apple"); queue.offer("orange"); queue.offer("pear"); queue.poll(); queue.poll(); queue.poll(); System.out.println(queue.poll()); }
A.apple
B.orange
C.pear
D.null
正确答案:D解析:
32.
(单选题)下列属于不合法Java标识符的是()。
A._avaj
B.5save
C.Avaj
D.$80
正确答案:B解析:
33.
(单选题)运行下列代码,输出为false的是:()。
A.
1
String st1 = "abc";
2
System.out.println("abc" == st1);
B.
1
String st2 = "abc";
2
System.out.println(st2.equals(new String("abc")));
C.
1
Integer i = 100;
2
System.out.println(100 == i);
D.
1
ArrayList list = new ArrayList();
2
System.out.println(list.contains(null));
正确答案:D解析:
34.
(单选题)下列代码编译和运行的结果是:
01
class SuperCalc {
02
protected static int multiply(int a, int b) {
03
return a * b;
04
}
05
}
06
class SubCalc extends SuperCalc {
07
public static int multiply(int a, int b) {
08
int c = super.multiply(a, b);
09
return c;
10
}
11
}
12
public class TestSuper {
13
public static void main(String[] args) {
14

SubCalc sc = new SubCalc();
15
System.out.println(sc.multiply(3, 4));
16
System.out.println(SubCalc.multiply(2, 2));
17
}
18
}
A.运行代码,但是没有输出
B.代码public static int multiply(int a, int b) {行,编译错误
C.代码int c = super.multiply(a, b);行,编译错误
D.代码System.out.println(sc.multiply(3, 4));行,编译错误
正确答案:C解析:
35.
(单选题)下面for语句,存在编译错误的是()。
A.for( ; ; ){}
B.for(int i=0; i < 100;i++){}
C.for(int i = 0, j=0; ;i++,j++){}
D.for(int i = 0; i < 10){}
正确答案:D解析:
36.
(单选题)下面不属于Java语言特点的是:
A.平台无关
B.面向对象
C.支持指针类型
D.垃圾回收机制
正确答案:C解析:
37.
(单选题)查看如下代码:
01
1. class HasStatic{
02
2. private static int x=100;
03
3. public static void main(String args[ ]){
04
4. HasStatic hs1=new HasStatic( );
05
5. hs1.x++;
06
6. HasStatic hs2=new HasStatic( );
07
7. hs2.x++;
08
8. hs1=new HasStatic( );
09
9. hs1.x++;
10
10. HasStatic.x--;
11
11. System.out.println(“x=”+x);
12
12. }
13
13.}
对于此代码,下列描述中,正确的是()。
A.5行不能通过编译,因为引用了私有静态变量
B.10行不能通过编译,因为x是私有静态变量
C.程序通过编译,输出结果为:x=103
D.程序通过编译,输出结果为:x=102
正确答案:D解析:
38.
(单选题)下列代码的运行结果是()。
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
}
A.peep
B.bark
C.meow
D.抛出运行时异常
正确答案:D解析:
39.
(单选题) 下列代码的输出结果是:()。
01
public class StaticFoo {
02
int num;
03
static int x;
04
public static void main(String[] args) {
05
StaticFoo foo1 = new StaticFoo ();
06
foo1.num++;
07
foo1.x++;
08
StaticFoo foo2 = new StaticFoo ();
09
foo2.num++;
10
foo2.x++;
11
StaticFoo foo3 = new StaticFoo ();
12
foo3.num++;
13
foo3.x++;
14
StaticFoo.x++;
15
System.out.print(foo3.num+",");
16
System.out.println(foo3.x);
17
}
18
}
A.3,3
B.1,3
C.3,4
D.1,4
正确答案:D解析:
40.
(单选题)下列代码编译和运行的结果是:
01

public static void main(String[] args) {
02
Float pi = new Float(3.14f);
03
if (pi > 3) {
04
System.out.print("pi is bigger than 3. ");
05
} else {
06
System.out.print("pi is not bigger than 3. ");
07
}
08
finally {
09
System.out.println("Have a nice day.");
10
}
11
}
A.编译失败
B.输出:pi is bigger than 3.
C.输出:pi is bigger than 3. Have a nice day
D.输出:pi is not bigger than 3. Have a nice day.
正确答案:A解析:
41.
(多选题)下面的方法属于StringBuffer的是:()。
A.size
B.insert
C.delete
D.length
正确答案:BCD解析:
42.
(多选题)查看如下代码:
1
public class Foo {
2
public void method(String str,int age){}
3
}
下列选项中,和 Foo 类中 method 方法重载的方法是()。
A.public int method(String str,int age){}
B.public void method(int year,String s){}
C.public int method(int year,String s){}
D.public int method(String str){}
正确答案:BCD解析:
43.
(多选题)请看下列代码:
1
package com.tarena;
2
public class Geodetics {
3
public static final double DIAMETER = 12756.32;
4
}
访问静态常量DIAMETER的方式正确的是:
A.
1
import com.tarena.Geodetics;
2
public class TerraCarta {
3
public double halfway(){
4
return Geodetics.DIAMETER/2.0;
5
}
6
}
B.
1
import com.tarena.Geodetics;
2
public class TerraCarta {
3
public double halfway(){
4
return DIAMETER/2.0;
5
}
6
}
C.
1
import com.tarena;
2
public class TerraCarta {
3
public double halfway(){
4
return Geodetics.DIAMETER/2.0;
5
}
6
}
D.
1
import com.tarena.*;
2
public class TerraCarta {
3
public double halfway(){
4
return Geodetics.DIAMETER/2.0;
5
}
6
}
正确答案:AD解析:
44.
(多选题)在Java语言中,下列说法正确的是:()。
A.StringBuffer和StringBuilder的区别在于:StringBuffer是线程安全的而StringBuilder不是。
B.String是不可变对象,而StringBuffer中封装的字符串数据是可以动态改变的。
C.判断两个StringBuilder对象的字符序列是否相同,可以调用其equlas方法进行比较。
D.String的重写了equals方法,重写的逻辑是:字符序列相同的String对象equals方法返回true。
正确答案:ABD解析:
45.
(多选题)在Java语言中,下列说法正确的是()。
A.一个接口可以继承多个接口
B.一个类可以继承多个类
C.一个类可以实现多个接口
D.一个类可以有多个子类
正确答案:ACD解析:
46.
(多选题)所谓“水仙花”数是一个整数等于各位数字立方的和,例如:153 = 1*1*1+5*5*5+3*3*3,下面的程序用于 输出2~1000内的水仙花数:
1
for (int n = 2; n <= 1000; n++) {
2
空白处
3
if (s == n) {
4
System.out.println(n);
5
}

6
}
下列选项中,空白处可以填入的代码是:()。
A.
1
int s = 0, n1 = n;
2
while (n1 > 0) {
3
int t = n1 % 10;
4
s += t * t * t;
5
n1 /= 10;
6
}
B.
1
int s = 0, n1 = n;
2
while (n1 > 0) {
3
int t = n1 / 10;
4
s+= t * t * t;
5
n1 %= 10;
6
}
C.
1
int s = 0;
2
for(int n1 = n; n1>0; n1 /= 10) {
3
int t = n1%10;
4
s += t * t * t;
5
}
D.
1
int s = 0;
2
for(int n1 = n; n1>0; n1 %= 10) {
3
int t = n1 / 10;
4
s += t * t * t;
5
}
正确答案:AC解析:
47.
(多选题)下列赋值语句中,会有编译错误的是()。
A.int a = 8888888888;
B.char b = 1000+300;
C.byte c = 100+30;
D.int d = 'a'+'b'+'c';
正确答案:AC解析:
48.
(多选题)下列关于HashMap的描述正确的是:
A.HashMap的Key和Value是以链表的方式存入对应的bucket
B.HashMap的查找方式是获取Key的hashCode值,通过hash算法确定存储的bucket,调用equals方法依次 与bucket中的Key进行比较
C.放入HashMap集合中的元素按照key的自然顺序排序
D.HashMap中的key是不可以的重复的
正确答案:ABD解析:
49.
(多选题)请看下列代码: Map map=new HashMap(); map.put("one",100); map.put("two",200); map.put("three",300); 遍历map对象中的每一个元素,下列选项正确的是:
A.Set set=map.keySet(); for(String key:set){ Integer value=map.get(key); System.out.println(key+”:”+value); }
B.List list=map.keyList(); for(String key:list){ Integer value=map.getKey(key); System.out.println(key+”:”+value); }
C.Set> set = map.entrySet(); for (Map.Entry per : set) { System.out.println(per.getKey() + ":" + per.getValue()); }
D.List list=map.entryList(); for(Entry per:list){ System.out.println(per.getKey() + ":" + per.getValue()); }
正确答案:AC解析:
50.
(多选题)题目代码的功能为:输出每个字符在一个字符串中出现的次数(不区分大小写)。
1
String str = "ewrwqFrewqfsadfdsfdsfs";
2
str=str.toLowerCase();
3
int max_length = 0;
4
while (str.length() > 0) {
5
《插入代码》
6
}
A.
1
int length = str.length();
2
char first=str.charAt(0);
3
String strNew = str.replaceAll(String.valueOf(first), "");
4
if (length>strNew.length()) {
5
max_length = length - strNew.length(); System.out.println(first+":"+max_length);
6
}
B.
1
int length = str.length();
2
char first=str.charAt(0);
3
String strNew = str.replaceAll(String.valueOf(first), "");
4
if (length>strNew.length()) {
5
max_length = length - strNew.length();
6
str = strNew; System.out.println(first+":"+max_length);
7
}
C.
1
int length = str.length();
2
String first = str.substring(0, 1);
3
String strNew = str.replaceAll(first, "");
4
if (length>strNew.length()) {
5
max_l

ength = length - strNew.length();
6
str = strNew;
7
System.out.println(first+":"+max_length);
8
}
D.
1
int length = str.length();
2
String first = str.substring(0, 1);
3
String strNew = str.replaceAll(first, "");
4
if (length>strNew.length()) {
5
max_length = length - strNew.length();
6
System.out.println(first+":"+max_length);
7
}
正确答案:BC解析:
关于我们 | 服务支持 | 咨询与反馈 | 最新动态 | 代理合作 | 名师堂
达内时代科技集团有限公司 2013-2014
中关村中心企业合作:62117598 UID中心企业合作:82168421、82168831

相关文档
最新文档