java考试题

TCSD——标准考试 2014年09月_JSD_JSD1408试题
(100分制,考试时间150分钟)
一、 单选(35小题共70.0分)
1.
关于下列代码说法不正确的是:
10. interface Foo {
11. int bar();
12. }
13.
14. public class Beta {
15.
16. class A implements Foo {
17. public int bar() { return 1; }
18. }
19.
20. public int fubar( Foo foo) { return foo.bar(); }
21.
22. public void testFoo() {
23.
24. class A implements Foo {
25. public int bar() { return 2; }
26. }
27.
28. System.out.println( fubar( new A()));
29. }
30.
31. public static void main( String[] argv) {
32. new Beta().testFoo();
33. }
34. }
A.
编译错误
B.
运行代码输出:2
C.
如果删除16,17,18行,运行代码应然输出:2
D.
如果删除24,25,26行,运行代码输出:1
2.
在Java语言中,下列说法正确的是:()。
A.
Java访问修饰符按照访问范围由低到高的排列顺序是public,default,protected,private
B.
private可以用于外部类的声明
C.
一个Java源文件中声明为public的外部类只能有一个
D.
protected声明的方法不可以被子类重写
3.
请看下列代码
public class Member{
private Long userId;
private String nickName;
//以下是getter和sett方法
……
}
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));
控制台的输出结果是:
A.
true
false
B.
false
true


C.
false
false
D.
true
ture


4.
下面关于final说法错误的是:()
A.
final修饰类时,该类不能被继承。
B.
final修饰方法时,该方法不能被重写。
C.
当引用到使用static final 修饰的常量时,将采用编译期绑定的方式。
D.
当使用final和abstract共同修饰一个类时,final应至于abstract之前。
5.
下列代码的输出结果是()
public static void main(String[] args) {
String test = "a1b2c3";
String[] tokens = test.split("\\d");
for (String s : tokens)
System.out.print(s + " ");
}
A.
a b c
B.
1 2 3
C.
a1b2c3
D.
a1 b2 c3
6.
关于下列代码说法正确的是:
public class Money {
private String country, name;
public String getCountry() {
return country;
}
}
class Yen extends Money {
public String getCountry() {
return super.country;
}
}
class Euro extends Money {
public String getCountry(String timeZone) {
return super.getCountry();
}
}
A.
Yen类编译正确
B.
Euro类编译正确
C.
Money类编译错误
D.
Yen和Money编译错误
7.
在Java中,Integer.MAX_VALUE表示:
A.
double型最大值
B.
int最大值
C.
long型最大值
D.
char型最大值
8.
运行下列程序:

Strin

g str = "**java***java*****java*";
String str1 = "java";
int index = 0;
while ((index = str.indexOf(str1, index)) != -1) {
System.out.print(index+””);
index += str1.length();
}
控制台输出的结果是:()。
A.
1 8 17
B.
2 9 18
C.
5 12 21
D.
6 13 22
9.
请看下列代码:
public interface A {
String DEFAULT_GREETING = "Hello World";
public void method1();
}
现有接口B,是A接口的子接口,下列选择中B接口的声明正确的是:
A.
public interface B extends A { }
B.
public interface B implements A {}
C.
public interface B instanceOf A {}
D.
public interface B inheritsFrom A { }
10.
请看下列代码:
public static void main(String[] args) {
<插入代码>
System.out.println(s);
}
如果程序输出的结果是4247,那么在<插入代码>处应该填入代码是()。
A.
String s = "123456789";
s = (s-"123").replace(1,3,"24") - "89";
B.
StringBuffer s = new StringBuffer("123456789");
s.delete(0,3).replace( 1,3, "24").delete(4,6);
C.
StringBuffer s = new StringBuffer("123456789");
s.substring(3,6).delete( 1 ,3).insert( 1, "24");
D.
StringBuilder s = new StringBuilder("123456789");
s.substring(3,6).delete( 1 ,2).insert( 1, "24");
11.
请看下列代码编译和运行的结果是()。
interface DeclareStuff {
public static final int EASY = 3;
void doStuff(int t);
}
public class TestDeclare implements DeclareStuff {
public static void main(String[] args) {
int x = 5;
new TestDeclare().doStuff(++x);
}
void doStuff(int s) {
s += EASY + ++s;
System.out.println("s=" + s);
}
}

A.
s=14
B.
s=16
C.
s=10
D.
编译失败
12.
类A,B和C的定义如下:

public class A {
public void f() {
System.out.println("A.f()");
}
}
public class B extends A {
public void f() {
System.out.println("B.f()");
}
}
public class C {
public void g(A a) {
System.out.println("g(A a)");
a.f();
}
public void g(B b) {
System.out.println("g(B b)");
b.f();
}
}

运行下面程序:
C c = new C();
A a = new B();
c.g(a);
输出的结果是:()。
A.
g(A a)
A.f()

B.
g(A a)
B.f()

C.
g(B b)
A.f()

D.
g(B b)
B.f()
13.
程序的执行结果是:
public class Test {
public static void main(String [] args){
System.out.println(“”+'a'+1);
}
}
A.
98
B.
a1
C.
971
D.
197
14.
下列语句创建对象的总个数是:()。

String s=”a”+”b”+”c”+”d”+”e”;

A.
1

B.
2

C.
3

D.
4

15.
在Java语言中,字符串“Java程序员”在内存中所占用的字节数是:()。
A.
10
B.
7
C.
13
D.
14
16.
class Card{}下列不属于Card类构造方法的是:()
A.
Card(){}

B.
public Card(){}

C.
publ

ic void Card(){}

D.
private Card(){}


17.
下列代码编译和运行的结果是()。
public class A {
public void start() {
System.out.println("TestA");
}
}
public class B extends A {
public void start() {
System.out.println("TestB");
}
public static void main(String[] args) {
((A) new B()).start();
}
}

A.
输出:TestA
B.
输出:TestB
C.
输出:TestA TestB
D.
编译错误
18.
关于下列代码说法正确的是:
class ClassA {
public int numberOfinstances;
protected ClassA(int numberOfinstances) {
this.numberOfinstances = numberOfinstances;
}
}
public class ExtendedA extends ClassA {
private ExtendedA(int numberOfinstances) {
super(numberOfinstances);
}
public static void main(String[] args) {
ExtendedA ext = new ExtendedA(420);
System.out.print(ext.numberOfinstances);
}
}
A.
运行后,输出420
B.
运行时抛出异常
C.
编译错误,所有的构造器必须是public的
D.
编译错误,构造器不能是private的
19.
下列表达式中,可以得到精确结果的是()。
A.
double d1 = 3.0 - 2.6;
B.
double d4 = 2.5 * 1.5;
C.
double d2 = 30/300;
D.
double d3 = 1/2 + 0.5;
20.
分析如下语句,说法错误的是()。
A.
break可用于跳出循环,当多层嵌套时,只用于跳出一层循环
B.
break即可以出现在循环语句中也可以出现在switch语句中
C.
continue可以用于跳出循环
D.
continue不能出现在switch语句中
21.
请看下列代码:
public String makinStrings() {
String s = "Fred";
s = s + "47";
s = s.substring(2, 5);
s = s.toUpperCase();
return s.toString();
}
调用makinString方法,得到的字符串长度是:

A.
1
B.
2
C.
3
D.
4
22.
实现Point类的equals方法,具体逻辑为:“成员变量x和y分别相等的Point对象被视为相等”。
public class Point {
private int x;
private int y;
...
public boolean equals(Object obj) {
《填入代码》
}
}
《插入代码》处应填入的代码正确的是:
A.
if(obj.x == this.x || obj.y == this.y){
return true;
}
return false;


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


23.
运行下列代码:

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(Arrays.toString(threeArr));

输出的结果是:()。
A.
[2,11,26,27,37,44,48,60,19,35,49,55,58,75,83,84,91,93];
B.
[2,11,19,26,27,35,37,44,48,49,55,58,60,75,83,84,91,93];
C.
[19,35,49,55,58,75,83,84,91,93,2,11,26,27,37,44,48,60];
D.
[2,19,11,35,26,49,27,55,37,58,44,75,48,83,60,84,91,93];
24.
请看下列代码:
interface Foo {
int bar();
}
public class Sprite {
public int fubar(Foo foo) {
return foo.bar();
}
public void testFoo() {
fubar(
<插入代码>
);
}
}
使类Sprite编译通过,在<插入代码>处应填入的代码是:
A.
Foo { public int bar() { return 1; } }
B.
new Foo { public int bar() { return 1; } }
C.
new Foo() { public int bar(){return 1; } }
D.
new class Foo { public int bar() { return 1; } }
25.
请看下列代码,出现错误的行是:()

public interface Cookie{
Cookie cookie=new Cart ("小面包","盼盼");
}
public class Cart implements Cookie{
private String name;
private String production;
public Cart(String name,String production){
https://www.360docs.net/doc/4613475344.html,=name;
this.production=production;
}
public void smell(){
cookie =new Cart("蛋黄派","达利园");
}
}
A.
第2行

B.
第4行

C.
第11行

D.
第12行

26.
下面关于interface,叙述错误的是:()
A.
一个interface可以继承多个interface

B.
接口中的方法可以由private修饰

C.
interface中可以定义static final 常量

D.
interface中可以无任何方法定义

27.
Java程序的执行过程中用到一套JDK工具,其中javac.exe是指()。
A.
Java语言编译器
B.
Java字节码解释器
C.
Java文档生成器
D.
Java类分解器
28.
请看下列代码:
public static void main(String[] args) {
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, 2013);
c.set(Calendar.MONTH, Calendar.FEBRUARY);
c.set(Calendar.DATE, 28);
<插入代码>
}
在<插入代码>处填入将Calendar表示的日期转换为Date表示的日期:
A.
Date d=c.getDate();
B.
Date d=c.getCalendar();
C.
Date d=c.getNow();
D.
Date d=c.getTime();
29.
请看下列代码:
package domain;
public class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public String toString() {
return "x=" + x + ",y=" + y;
}
}
和:
Point p = new Point(1, 2);
System.out.println(p);
不覆盖toString方法和覆盖toString方法,程序的输出结果分别是:

A.
domain.Point@hashCode和x=1,y=2
B.
x=1,y=2和domain.Point@hashCode
C.
x=1,y

=2和x=1,y=2
D.
domain.Point@hashCode和domain.Point@hashCode
30.
下列代码的输出结果是()。

int j=0;
for(int i=0;i<100;i++){
j=j++;
}
System.out.println(j);

A.
0

B.
99

C.
100

D.
101


31.
请看下列代码:
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”,那么<插入代码>处应填入代码是:
A.
p.setWeight(420);
B.
Payload.setWeight(420);
C.
p = new Payload(420);
D.
p = new Payload();
p.setWeight(420);
32.
请看下列程序的输出结果是:
public class Item {
private String desc;
public String getDescription() {
return desc;
}
public void setDescription(String d) {
desc = d;
}
public static void modifyDesc(Item item, String desc) {
item = new Item();
item.setDescription(desc);
}
public static void main(String[] args) {
Item it = new Item();
it.setDescription("Gobstopper");
Item it2 = new Item();
it2.setDescription("Fizzylifting");
modifyDesc(it, "Scrumdiddlyumptious");
System.out.println(it.getDescription());
System.out.println(it2.getDescription());
}
}
A.
Scrumdiddlyumptious
Scrumdiddlyumptious
B.
Scrumdiddlyumptious
Fizzylifltng
C.
Gobstopper
Scrumdiddlyumptious
D.
Gobstopper
Fizzylifting
33.
下列代码运行的结果是()。

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";
}

A.
foofoofoofoofoo
B.
foobarfoobarbar
C.
foobarfoofoofoo
D.
foobarfoobarfoo
34.
下列代码的输出结果是()。
abstract class Vehicle {
public int speed() {
return 0;
}
}
class Car extends Vehicle {
public int speed() {
return 60;
}
}
class RaceCar extends Car {
public int speed() {
return 150;
}
}
public class TestCar {
public static void main(String[] args) {
RaceCar racer = new RaceCar();
Car car = new RaceCar();
Vehicle vehicle = new RaceCar();
System.out.println(racer.speed() + ", " + car.speed() + ", "
+ vehicle.speed());
}
}

A.
0, 0,0
B.
150, 60, 0

C.
150, 150, 150
D.
抛出运行时异


35.
程序的执行结果是:
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");
}
}


A.
true
true
B.
true
false
C.
false
true
D.
false
false
二、 多选(5小题共10.0分)
1.
请看下列代码:
class One {
public One foo() {
return this;
}
}
class Two extends One {
public One foo() {
return this;
}
}
class Three extends Two {
<插入代码>
}
下列选项中的代码,放置在<插入代码>处无编译错误的是:
A.
public void foo() { }
B.
public Object foo() { return this; }
C.
public Two foo() { return this; }
D.
public One foo() { return this; }
2.
请看下列代码:
package com.tarena;
public class Geodetics {
public static final double DIAMETER = 12756.32;
}
访问静态常量DIAMETER的方式正确的是:
A.
import com.tarena.Geodetics;
public class TerraCarta {
public double halfway(){
return Geodetics.DIAMETER/2.0;
}
}
B.
import com.tarena.Geodetics;
public class TerraCarta {
public double halfway(){
return DIAMETER/2.0;
}
}
C.
import com.tarena;
public class TerraCarta {
public double halfway(){
return Geodetics.DIAMETER/2.0;
}
}
D.
import com.tarena.*;
public class TerraCarta {
public double halfway(){
return Geodetics.DIAMETER/2.0;
}
}
3.
在Java语言中,下列说法正确的是()。
A.
一个接口可以继承多个接口
B.
一个类可以继承多个类
C.
一个类可以实现多个接口
D.
一个类可以有多个子类
4.
下面的方法属于StringBuffer的是:()。
A.
size
B.
insert
C.
delete
D.
length
5.
查看如下代码:

class A {
protected int method (int a, int b) {
return 0;
}


下列选项中,可以在 A 的子类中使用的是()。
A.
public int method (int a, int b) { return 0; }
B.
private int method(int a, int b) { return 0; }
C.
private int method(int a, long b) { return 0; }
D.
public short method(int a, int b) { return 0; }
三、 完形填空(2小题共20.0分)
1.
ScoreManager类实现了成绩管理系统。该系统有如下功能供选则:录入成绩 ,成绩列表 ,查询成绩,退出。当用户在控制台输入1,用户选择的功能为录入成绩;输入2,用户选择的功能为成绩列表;输入3,用户选择的功能为根据姓名查找成绩;输入4,退出。
ScoreManager类代码如下:
public class ScoreManager {
public static void main(String[] args) {
int numOfStudents = 10;
//

学生名字信息数组
String[] students = NameUtils.randomNames(numOfStudents);
int[] scores = new int[numOfStudents];//学生成绩数组
//使用Scanner接收控制台的输入信息
空白处1
System.out.println("**********欢迎进入成绩管理系统**********");
while (true) {
System.out.println("
请选择功能:1——成绩录入,2——成绩列表,3——成绩查询,4——退出");
String c = scanner.next().trim();
if ("1".equals(c)) {
System.out.println("开始录入成绩: ");
for (int i = 0; i < students.length; i++) {
System.out.print((i + 1) + ". 学生姓名:" + students[i]
+ ", 成绩:?");
//从控制台接收到学生成绩
空白处2
}
System.out.println("录入完毕。");
} else if ("2".equals(c)) {
int avg = 0;
for (int i = 0; i < scores.length; i++) {
avg += scores[i];
}
//计算学生的评价成绩
空白处3
System.out.println(StringUtils.rightPad("编号", 20, " ")
+ StringUtils.rightPad("姓名", 20, " ")
+ StringUtils.rightPad("成绩", 20, " "));
System.out.println(StringUtils.repeat("-", 30));
for (int i = 0; i < students.length; i++) {
System.out.println(StringUtils
.rightPad(i + 1 + "", 10, " ")
+ StringUtils.rightPad(students[i], 10, " ")
+ StringUtils.rightPad(scores[i] + "", 10, " "));
}
System.out.println(StringUtils.repeat("-", 30));
System.out.println("平均成绩: " + avg);
} else if ("3".equals(c)) {
System.out.print("请输入您要查询的学生姓名: ");
String student = scanner.next().trim();
int i = 0;
for (; i < students.length; i++) {
//如果查找到某个学生的信息,退出当前循环
空白处4
}
if ( 空白处5 ) {
System.out.println((i + 1) + ". 学生姓名:" + students[i]
+ ", 成绩:" + scores[i]);
} else {
System.out.println("对不起,找不到学员的信息。");
}
} else if ("4".equals(c)) {
System.out.println("**********谢谢使用**********");
break;
}
}
scanner.close();
}
}


(1).
下列选项中,

能填入空白处1的代码是( )
A.
Scanner scanner = new Scanner(System.out);
B.
Scanner scanner = new Scanner(System.in);
C.
Scanner scanner = new Scanner(new FileInputStream(System.in));
D.
Scanner scanner = new Scanner(new FileOutputStream(System.out));
(2).
下列选项中,能填入空白处2的代码是( )
A.
scores[i] = scanner.nextInt();
B.
scores[i] = scanner.next();
C.
scores[i] = scanner.nextDouble();
D.
scores[i] = scanner.nextString();
(3).
下列选项中,能填入空白处3的代码是( )
A.
avg *= scores.length;
B.
avg /= scores.length;
C.
avg *= scores.length-1;
D.
avg /= scores.length-1;
(4).
下列选项中,能填入空白处4的代码是( )
A.
if (student.equalsIgnoreCase(students[i-1])) {
break;
}
B.
if (student.equalsIgnoreCase(students[i])) {
continue;
}
C.
if (student.equalsIgnoreCase(students[i-1])) {
continue;
}
D.
if (student.equalsIgnoreCase(students[i])) {
break;
}
(5).
下列选项中,能填入空白处5的代码是( )
A.
scores.length < scores.length-1
B.
scores.length < scores.length
C.
i < students.length
D.
i < students.length-1
2.
阅读理解
public class A {
public A() {
System.out.print("A ");
}
public A(String s) {
System.out.print(s);
}
public void fun() {
System.out.println("A.fun()");
}
}
public class B extends A {
public B() {
System.out.print("B ");
}
public B(String s) {
super(s);
}
public void fun() {
System.out.println("B.fun()");
}
public void sun(){
System.out.println("B.sun()");
}
public static void Main() {
A a = new B();
a.fun();
}
}
(1).
下列关于上述代码中构造方法的描述,错误的是()。
A.
实例化对象 a 时,将默认调用父类的无参构造方法
B.
类 B中使用 super 关键字,是为了调用父类的含有一个参数的构造方法
C.
实例化对象 a 时,父类A和子类B的构造方法都会被调用到
D.
实例化父类对象时,调用父类 A 的构造方法;实例化子类对象时,则只调用子类B的构造方法
(2).
该代码运行后,输出为:()。
A.
A B A.fun()
B.
A B B.fun()
C.
B A A.fun()
D.
B A B.fun()
(3).
如果 main 方法中如此调用:
public static void main(String[] args)
{
A a = new B("Hello,");
a.fun();
}
其他代码不变,该代码运行后,输出为:()。
A.
A A.fun()
B.
B A.fun()
C.
Hello,A.fun()
D.
Hello,B.fun()
(4).
如果 main 方法中如此调用:
public static void main(String[] args)
{
A a = new A();
a.sun();
}
其它代码不变,下列说法正确的是:()。
A.
运行输出结果为:A B.sun()
B.
运行输出结果为:A B B.sun()
C.
运行输出结果为:B A B.sun()
D.
编译错误

(5).

列关于上述代码的描述,正确的是()。
A.
如果将A类定义成public abstract class A,那么方法fun必须定义成抽象方法
B.
如果将A类定义成public abstract class A,那么A类中必须有一个抽象方法
C.
如果将A类中的方法fun定义成public abstract void fun(),那么A类必须是抽象类
D.
如果将A类定义成public abstract class A,那么A类应然可以实例化对象

相关文档
最新文档