达内 jsd1411第一次月考题
考试请使用火狐,谷歌浏览器!
序
号
1 考试场次 2014_12月月考_12
月29日_JAVA 试卷名称 2014年12月_JSD_JSD1411 分数 考试时间 2014-12-29 18:30:00
考试详情
考试场次:2014_12月月考_12月29日_JAVA 试卷名称:2014年12月_JSD_JSD1411
1. 下列关于内存回收的说明正确的是:
A. 程序员必须创建一个线程来释放内存
B. 内存回收程序负责释放无用内存
C. 内存回收程序允许程序员直接释放内存
D. 内存回收程序可以在指定的时间释放内存对象
正确答案:B
2.
下列代码的输出结果是()。
boolean b=true?false:true==true?false:true;
System.out.println(b);
A.
true
B.
false
C.
null
D.
3. 下列属于不合法Java标识符的是()。
A.
_avaj
B.
5save
C.
Avaj
D.
$80
正确答案:B
4.
运行下面程序:
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
5. 下面关于final说法错误的是:()
A. final修饰类时,该类不能被继承。
B. final修饰方法时,该方法不能被重写。
C. 当引用到使用static final 修饰的常量时,将采用编译期绑定的方式。
D. 当使用final和abstract共同修饰一个类时,
final应至于abstract之前。 正确答案:D
6. 程序的执行结果是: public class Test { public static void main(String [] args){
System.out.println(“”+'a'+1);
}
}
A. 98
B. a1
C. 971
D. 197
正确答案:B
Card(){}
B.
public Card(){}
C.
public void Card(){}
D.
private Card(){}
正确答案:C
8. 数据类型int、char和double所占用内存字节数分别是:()。 A. 4
、2和
8
B. 2、2和
4
C. 2、1和
8
D. 4、4和4
正确答案:A
9. 下面不属于Java语言特点的是:
A. 平台无关
B. 面向对象
C. 支持指针类型
D. 垃圾回收机制
正确答案:C
System.out.println(sdf.format(c.getTime()));
输出的结果是:()。
A. 2012-10-1
B. 2012-10-01
C. 2012-09-30
D. 2012-9-30
正确答案:B
11. 下面关于interface,叙述错误的是:()
A.
一个interface可以继承多个interface
B.
接口中的方法可以由private修饰
C.
interface中可以定义static final 常量
D.
interface中可以无任何方法定义
正确答案:B
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
正确答案:D
}
public String getName() {
return name;
}
}
class Tree extends Plant {
public void growFruit() {
}
public void dropLeaves() {
}
}
下列说法正确的是:
A. 在Tree类中添加代码:public Tree() { Plant(); },编译将通过
B. 在Plant类中添加代码:public Plant() { Tree(); },编译将通过
C. 在Plant类中添加代码:public Plant() { this(”fern”); },编译将通过
D. 在Plant类中添加代码:public Plant() { Plant(”fern”); },编译将通过
正确答案:C
14.
类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()
正确答案:B
15. 程序的执行结果是:
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
正确答案:A
16. 运行下面的程序:
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"))+" ");
}
}
控制台的输出结果是:()。
A. bcd. cde. efg.
B. bc cd ef
C. bcd.exe cde.exe efg.exe
D. bcd cde efg
正确答案:D
17. 请看下列代码的输出结果是:
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); } }
A. first second third snootchy 420
B. third second first snootchy 420 C. third first second snootchy 420
D. first second first third snootchy 420 正确答案:B
18.
下列属于不合法Java标识符的是()。
A. _mem
B. 12a
C. M12
D. $12
正确答案:B
19. 下列代码编译和运行的结果是:
public static void main(String[] args) { Float pi = new Float(3.14f);
if (pi > 3) {
System.out.print("pi is bigger than 3. "); } else {
System.out.print("pi is not bigger than 3. "); }
finally {
System.out.println("Have a nice day."); }
}
A. 编译失败
B. 输出:pi is bigger than 3.
C. 输出:pi is bigger than 3. Have a nice day
20.
下列代码的输出结果是()
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
正确答案:A
}
编译,运行的结果是:()。
A.
Hello World
B.
无输出
C.
编译错误
D. 抛出运行时异常
正确答案:B
22.
运行下列程序:
String str = "**oracle***oracle*****oracle***";
String str1 = "oracle";
int index = 0;
while ((index = str.indexOf(str1, index)) != -1) {
System.out.print(index+””);
index += str1.length();
}
控制台输出的结果是:()。
A.
1 10 21
B.
2 11 22
C.
3 13 23
D.
5 13 22
正确答案:B
23.
编译和运行以下代码的结果为()。
public class MyMain{
public static void main(String argv){
System.out.println("Hello cruel world");
}
}
A.
编译错误
B.
运行输出 "Hello cruel world"
C.
编译无错,但运行时指示没有定义构造方法
D.
24. 实现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;
正确答案:D
Goban b = new Goban();
b.go();
Stone c = new Stone();
c.go();
}
}
class Sente implements Go {
public void go() {
System.out.println("go in Sente");
}
}
class Goban extends Sente {
public void go() {
System.out.println("go in Goban");
} }
class Stone extends Goban implements Go {
}
interface Go {
public void go();
}
A. go in Goban
go in Sente
go in Sente
B. go in Sente
go in Sente
go in Goban
C. go in Sente
go in Goban
go in Goban
D. go in Goban
go in Goban
go in Sente
正确答案:C
26. 下列代码的输出结果是:
String str1 = "WhatisJava";
String str2 = "WhatisJava";
System.out.print(str1.equals( str2));
System.out.print(",");
String str3 = new String("WhatisJava");
System.out.println(str1.equals(str3));
A. true,false
B. false,false
C. false,true
D. true,true
正确答案:D
27.
下列代码的输出结果是:
public class Blip {
protected int blipvert(int x) {
return 0;
}
}
class Vert extends Blip {
}
在处填入选项中的代码,使Vert类没有编译错误的是()。
A.
public int blipvert(int x) { return 0; }
B.
private int blipvert(int x) { return 0; }
C.
private void blipvert(int x) { return 0; }
D.
protected long blipvert(int x) { return 0; }
正确答案:A
A. Java面向对象
B. Java虚拟机
C. Java垃圾回收机制 D. Java
编译器
正确答案:B
29.
请看下列代码:
interface Data { public void load(); }
abstract class Info { public abstract void load(); }
下列选项中,能正确使用Data接口和Info类的是()。
A.
public class Employee extends Info implements Data {
public void load() { /*do something*/ }
}
B.
public class Employee implements Info extends Data {
public void load() { /*do something*/ }
}
C.
public class Employee implements Info extends Data {
public void Data.load() { /*d something */ }
public void load() { /*do something */ }
}
D.
public class Employee extends Info implements Data {
30.
运行下列程序:
String 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
正确答案:B
31. 请看下列代码
public class Foo {
public void method(String str,int age){}
}
和Foo类中method方法重载的方法是:
A. public int method(String str,int age){}
B. public void method(String s,int year){}
C. public void method(int year,String s){}
D. public int method(int year,String s){}
正确答案:CD
32. 在处,填入下列代码编译正确的是:
public void foo(int[] x) {
}
A. foreach(int z : x) System.out.println(z);
B. for(int z : x) System.out.println(z);
33.
查看如下代码:
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; }
正确答案:AC
34. 请看下列代码:
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; }
正确答案:CD
35. 下列关于HashMap的描述正确的是:
A. HashMap的Key和Value是以链表的方式存入对应的bucket
B. HashMap的查找方式是获取Key的hashCode值,通过hash算法确定存储的bucket,调用equals方法依次与bucket中的Key进行比较
C. 放入HashMap集合中的元素按照key的自然顺序排序
D. HashMap中的key是不可以的重复的
正确答案:ABD
36.
阅读理解
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的构造方法
正确答案:D
(2).
该代码运行后,输出为:()。
A.
A B A.fun()
B.
A B B.fun()
C.
B A A.fun()
D.
B A B.fun()
正确答案:B
(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()
正确答案:D
(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.
编译错误
正确答案: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类应然可以实例化对象
正确答案:C
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
+ ", 成绩:?");
//从控制台接收到学生成绩
空白处2
}
System.out.println("录入完毕。");
} else if ("2".equals(c)) {
int avg = 0;
for (int i = 0; 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
.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
//如果查找到某个学生的信息,退出当前循环 空白处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)); 正确答案:B
(2). 下列选项中,能填入空白处2的代码是( )
A.
scores[i] = scanner.nextInt();
B.
scores[i] = scanner.next();
C.
scores[i] = scanner.nextDouble();
D.
scores[i] = scanner.nextString();
正确答案:A
(3). 下列选项中,能填入空白处3的代码是( )
A.
avg *= scores.length;
B.
avg /= scores.length;
C.
avg *= scores.length-1;
D.
avg /= scores.length-1;
正确答案:B
(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;
}
正确答案:D
(5). 下列选项中,能填入空白处5的代码是( )
A.
scores.length
B.
scores.length
C.
i
D.
i
正确答案:C
38.
下面的程序用于随机输出5个不同的字母
public static void main(String[] args) {
char[] letters = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
int len = letters.length;
char[] chs = new char[5];
空白处1
Random rd = new Random();
for (int i = 0; i
int index;
do {
空白处2
} while ( 空白处3 ); 空白处4
空白处5
}
System.out.println(Arrays.toString(chs)); }
(1).
下列选项中,能填入空白处1的代码是( )
A.
boolean[] flags = new boolean[len];
B.
boolean[] flags = new boolean[]{};
C.
boolean[] flags = new boolean[5];
D.
boolean[] flags = new boolean[];
正确答案:A
(2).
下列选项中,能填入空白处2的代码是( )
A.
index = rd.nextInt();
B.
index = rd.nextInt(5);
C.
index = rd.nextInt(len + 1);
D.
index = rd.nextInt(len);
正确答案:D
(3).
下列选项中,能填入空白处3的代码是( )
A.
!flags[index]
B.
!flags[i]
C.
flags[index]
D.
flags[i]
正确答案:C
(4).
下列选项中,能填入空白处4的代码是( )
A.
chs[i] = letters[index];
B.
chs[i] = letters[i];
C.
chs[index] = letters[i];
D. chs[index] = letters[index];
正确答案:A
(5).
下列选项中,能填入空白处5的代码是( )
A.
flags[i] = true;
B.
flags[i] = false;
C.
flags[index] = true;
D.
flags[index] = false;
正确答案:C