版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、考试请使用火狐,谷歌浏览器! 序号考试场次试卷名称分数考试时间12014_11月月考_11月27日_JAVA2014年11月_JSD_JSD14102014-11-27 18:30:00考试详情 考试场次:2014_11月月考_11月27日_JAVA 试卷名称:2014年11月_JSD_JSD1410 1. 关于String 和 StringBuffer 下面说法正确的是()。 A. String操作字符串不改变原有字符串的内容 B. StringBuffer连接字符串速度没有String 快 C. String 可以使用append方法连接字符串 D. StringBuffer 在java.
2、util包中 正确答案:A 2. 类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 c
3、lass 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)");
4、160; 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 3. 运行下列代码,输出为false的是:()。A. String st1 = "abc"System.out.println("abc"
5、 = st1); B. String st2 = "abc"System.out.println(st2.equals(new String("abc"); C. Integer i = 100;System.out.println(100 = i); D. ArrayList list = new ArrayList();System.out.println(list.contains(null); 正确答案:D 4. List类的对象list中的元素为:0, 1, 2, 3, 4, 5, 6, 7, 8, 9,现在想返回该list对象的子集合5,6,
6、7,8,需要做的操作是:A. list.subList(5, 8);B. list.subList(5, 9);C. list.subList(4, 8);D. list.subList(4, 9);正确答案:B 5. 请看下列代码:interface Foo int bar();public class Sprite public int fubar(Foo foo) return foo.bar(); public void testFoo() fubar( <插
7、入代码> ); 使类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; 正确答案:C 6. 运行下面的程序:Calendar c = Calendar.getInstance();c.set(Calendar.YEAR, 2012);c.set(C
8、alendar.MONTH, Calendar.SEPTEMBER);c.set(Calendar.DATE, 31);SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");System.out.println(sdf.format(c.getTime(); 输出的结果是:()。A. 2012-10-1B. 2012-10-01C. 2012-09-30D. 2012-9-30正确答案:B 7. 关于下列代码说法正确的是:public class Money private String countr
9、y, 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. Mo
10、ney类编译错误D. Yen和Money编译错误正确答案:B 8. 下面关于final说法正确的是:()。A. final修饰类时,该类能被继承。 B. final修饰方法时,该方法能被重写。 C. 当使用static final 修饰的常量时,将采用编译期绑定的方式。 D. 当使用final和abstract共同修饰一个类时,final应至于abstract之前。 正确答案:C 9. 下面的代码用于对数组arr实现冒泡排序: for (int i = 0; i < arr.length - 1; i+) boolean isSwap =
11、false; 空白处 if (!isSwap) break; 下列选项中,空白处可以填入的代码是:()。A. for (int j = arr.length - 1; j > i; j-) if (arrj < arrj - 1)
12、160; int temp = arrj; arrj = arrj - 1; arrj - 1 = temp; isSwap = true; B. for (int j = arr.length - 1; j > 0; j-) if (arrj < arrj - 1)
13、0; int temp = arrj; arrj = arrj - 1; arrj - 1 = temp; isSwap = true; C. for (int j = i + 1; j< arr.length; j+) if (arrj < arrj - 1)
14、 int temp = arrj; arrj = arrj - 1; arrj - 1 = temp; isSwap = true; D. for (int j = i; j< arr.length; j+) if (arrj < arrj - 1)
15、160; int temp = arrj; arrj = arrj - 1; arrj - 1 = temp; isSwap = true; 正确答案:A 10. 类Super及Sub定义如下: public class Super private void f() System.out
16、.println("Super.f()"); public void g() f(); public void k() f(); public class Sub extends Super private void f() System.o
17、ut.println("Sub.f()"); public void k() f(); 运行下列语句: Super obj = new Sub();obj.g();obj.k(); 输出的结果是:()。A. Sub.f()Sub.f() B. Sub.f()Super.f() C. Super.f()Sub.f() D. Super.f()Super.f()正确答案:C 11. 关于下列代码说法不正确的是:10. interface Foo 11.
18、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.3
19、1. public static void main( String argv) 32. new Beta().testFoo();33. 34. A. 编译错误B. 运行代码输出:2C. 如果删除16,17,18行,运行代码应然输出:2D. 如果删除24,25,26行,运行代码输出:1正确答案:A 12. 运行下列程序: String str = "*java*java*java*" String str1 = "java" int index
20、 = 0; while (index = str.indexOf(str1, index) != -1) System.out.print(index+”); index += str1.length(); 控制台输出的结果是:()。A. 1 8 17B. 2 9 18C. 5 12 21D. 6 13 22正确答案:B 13
21、. 请看下列代码: public String makinStrings() String s = "Fred" s = s + "47" s = s.substring(2, 5); s = s.toUpperCase(); return s.toString(); 调用makinString方法,得到的字符串长度是: A. 1B. 2C. 3D. 4正确答案:C 14. 下列类的定义,错误的是()。 A. public class Test extend
22、s Object B. final class Operators C. class Point D. void class Point 正确答案:D 15. 以下程序的输出结果是: ()。 public class Super public Super() System.out.println("Super "); public class Sub extends Super public Sub() System.out.println("Sub");
23、60;public static void main(String args) Super fc = new Super(); Sub cc = new Sub(); A. Super Super Sub B. Super Sub C. Sub Super D. Super Sub Sub 正确答案:A 16. 请看下列代码:public class Plant private String name; public Plant(String name) = name; pu
24、blic 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. 在Pl
25、ant类中添加代码:public Plant() Plant(”fern”); ,编译将通过正确答案:C 17. 下列代码编译和运行的结果是:class SuperCalc protected static int multiply(int a, int b) return a * b; class SubCalc extends SuperCalc public static int multiply(int a, int b) int c = super.multiply(a, b); return c;
26、public class TestSuper public static void main(String args) SubCalc sc = new SubCalc(); System.out.println(sc.multiply(3, 4); System.out.println(SubCalc.multiply(2, 2); A. 运行代码,但是没有输出B. 代码public static int multiply(int a, int b) 行,编译错误C. 代码int c = super.multiply(a, b);行
27、,编译错误D. 代码System.out.println(sc.multiply(3, 4);行,编译错误正确答案:C 18. 下列属于不合法Java标识符的是()。A. _avaj B. 5save C. Avaj D. $80 正确答案:B 19. 下列代码的输出结果是()。 boolean b=true?false:true=true?false:true; System.out.println(b); A. true B. false C. null D. 空字符串 正确答案:B 20. 程序执行的结果是()。 public class Test &
28、#160; String name="Tom" public Test(String name) name=name; public static void main(String args) Test t = new Test("Jack"); &
29、#160; System.out.println(); A. null B. Tom C. Jack D. " " 正确答案:B 21. 下面关于interface,叙述错误的是:()A. 一个interface可以继承多个interface B. 接口中的方法可以由private修饰 C. interface中可以定义static final 常量 D. interface中可以无任何方法定义 正确答案:B 22. 下列不属于Collection接口的方法的是:
30、A. clearB. containsC. removeD. listIterator正确答案:D 23. 请看下列代码: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. p
31、ublic interface B inheritsFrom A 正确答案:A 24. 下面的程序可以输出1100内前10个3的倍数: for (int i = 1, count = 0; i < 100; i+) if (i % 3 = 0) System.out.println(i); &
32、#160; (空白处) 下列选项中,空白处可以填入的代码是()。A. if (count+ >= 10) break;B. if (+count >= 10) break;C. if (count+ >= 10) continue;D. if (+count >= 10) continue;正确答案:B 2
33、5. 在Java语言中,下列说法正确的是:()。A. Java访问修饰符按照访问范围由低到高的排列顺序是public,default,protected,privateB. private可以用于外部类的声明C. 一个Java源文件中声明为public的外部类只能有一个D. protected声明的方法不可以被子类重写正确答案:C 26. 下面关于数组的声明语句中,有编译错误的是:()。A. int arr = new int1,2,3;B. int arr = null;arr = 1,2,3,4,5;C. int arr = new int1,2,3,4,5,6D. int arr = n
34、ew int2;正确答案:B 27. 请看下列代码,出现错误的行是:() public interface Cookie Cookie cookie=new Cart ("小面包","盼盼"); public class Cart implements Cookie private String name; pr
35、ivate String production; public Cart(String name,String production) =name; duction=producti
36、on; public void smell() cookie =new Cart("蛋黄派","达利园"); A. 第2行 B. 第4行 C. 第11行 D. 第12
37、行 正确答案:D 28. 下列代码的输出结果是()。 public static void main(String args) int one=new int4,6,8; int two=new int1,3,5,7,9; System.arraycopy(one, 1, two, 2, 2); System.out.println(Arrays.toString(two); A. 1, 3, 7, 4, 6 B.
38、1, 3, 5, 7, 8 C. 1, 3, 5, 6, 9 D. 1, 3, 6, 8, 9 正确答案:D 29. 有变量声明如下: short b = 120; 下列语句中,错误的是()。 A. short s = b; B. int i = b; C. byte s1 = b; D. long l = b; 正确答案:C 30. 下列代码的输出结果是() public static void main(String args)
39、160; String test = "a1b2c3" String tokens = test.split("d"); for (String s : tokens) System.out.print(s + " ");
40、; A. a b c B. 1 2 3 C. a1b2c3 D. a1 b2 c3 正确答案:A 31. 查看如下代码: class A protected int method (int a, int b) return 0; 下列选项中,可以在 A 的子类中使用的是()。 A. public int method (int a, int b) retu
41、rn 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 32. 查看如下代码: public class Foo public void method(String str,int age) 下列选项中,和 Foo 类中 method 方
42、法重载的方法是()。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 33. 在<插入代码>处,填入下列代码编译正确的是: public void foo(int x) <插入代码> A. for
43、each(int z : x) System.out.println(z);B. for(int z : x) System.out.println(z);C. while( x.hasNext() System.out.println( x.next();D. for( int i=0; i< x.length; i+ ) System.out.println(xi);正确答案:BD 34. 下列关于HashMap的描述正确的是:A. HashMap的Key和Value是以链表的方式存入对应的bucketB. HashMap的查找方式是获取Key的hashCode值,通过hash算法确
44、定存储的bucket,调用equals方法依次与bucket中的Key进行比较C. 放入HashMap集合中的元素按照key的自然顺序排序D. HashMap中的key是不可以的重复的正确答案:ABD 35. 在Java语言中,下列说法正确的是()。A. 一个接口可以继承多个接口B. 一个类可以继承多个类C. 一个类可以实现多个接口D. 一个类可以有多个子类正确答案:ACD 36. 歌德巴赫猜想的近似证明 歌德巴赫猜想是说任何一个大于2的偶数都能表示为两个素数之和,请编写一个Java程序,验证1100内歌德巴赫猜想的正确性。 public class Guess
45、60; public static void main(String args) System.out.println("在1100范围内,现在开始证实哥德巴赫猜想:"); if (testifyGuess(1, 100) System.out.println("
46、在 1100范围内,哥德巴赫猜想是正确的。"); else System.out.println("哥德巴赫猜想是错误的"); /* *
47、判断1100范围内的所有偶数是否符合哥德巴赫猜想,符合则返回true,反之则返回false */ public static boolean testifyGuess(int low, int high) int i, j = 0; boolean flag = true;
48、160; for (i = low; i <= high; i+) if ( 空白处1 ) / 在1100之间选取大于2的偶数进行哥德巴赫猜想测试
49、 if (isGoldbach(i) j+; / j用来控制输出格式 ,每行输出5个数据
50、160; if (j = 5) System.out.println();
51、60; j = 0;
52、 else flag = false; break; &
53、#160; return flag; /* *判断参数a是否符合哥德巴赫猜想 */ public static boolean isGoldba
54、ch(int a) int i; boolean flag = false; for (i = 1; 空白处2 ; i+) &
55、#160; / 根据试题分析中的表达式,传入相关的两个参数 if ( 空白处3 )
56、60; flag = true; System.out.print(a + "=" + i + "+" + (a - i) + " "); &
57、#160; 空白处4
58、; return flag; /* * 判断参数i是否是素数,是则返回true反之则返回false */ public static boolean isPrime(int i) int n; bool
59、ean flag = true; / 1本身不是素数,因此需把这个特殊的数字抛出 if (1 = i)
60、 flag = false; /* * 质数又称素数。指在一个大于1的自然数中,除了1和此整数自身外,不能被其他自然数整除数 * 判断i是否是素数的一个方法是看2i-1之间有其因子(能被2整除), * 有则不是素数返回false,反之则返回tr
61、ue */ for ( 空白处5 )
62、160; if (i % n = 0) flag = false; break;
63、0; return flag; (1). 下列选项中,能填入空白处1的代码是( ) A. i % 2 = 0 && i > 2 B. i % 2 = 0 && i < 2 C. i / 2 = 0 && i > 2 D. i / 2 = 0 && i < 2 正确答案:A (2). 下列选项中,能填入空白处2的代码是( ) A.
64、 i <= a % i; B. i <= a / i; C. i <= a % 2; D. i <= a / 2; 正确答案:D (3). 下列选项中,能填入空白处3的代码是( ) A. isPrime(i-1) && isPrime(a - i) B. isPrime(i) && isPrime(a + i) C. isPrime(i) && isPrime(a - i) D. isPrime(i) && isPrime(a) 正确答案:C (4). 下列选
65、项中,能填入空白处4的代码是( ) A. final; B. break; C. continue; D. static; 正确答案:B (5). 下列选项中,能填入空白处5的代码是( ) A. n = 2; n <= i - 1; n+ B. n = 2; n <= i; n+ C. n = 1; n <= i - 1; n+ D. n = 1; n <= i; n+ 正确答案:A 37. 有一个父类Account表示银行账户。银行账户又分为储蓄账户(SavingAccount)和支票账户(Che
66、ckingAccount)。两种账户的区别是计算活期年利息的方式不同:有 储蓄账户:利率为:0.0036 支票账户:¥0¥20000 利率为:0.0036 ¥20000¥40000 利率为:0.0037
67、60; ¥40000¥80000 利率为:0.0038 ¥80000以上 利率为:0.0040 计算利息额公式为:利息= 余额×利率 以下是Account(帐户)和SavingAccount(储蓄账户)中的代码实现,根据所给代码推断出各个空白处应该填入代码。 public abstract class Acc
68、ount private String idCard; private double balance; /Account类构造方法 空白处1 public String getI
69、dCard() return idCard; public void setIdCard(String idCard) this.idCard = idCard; /给出balance的getter和setter方法
70、; 空白处2 public abstract double getInterest(); public class SavingAccount extends Account public SavingAccount(String name, double balance) /调
71、用父类的构造方法 空白处3 /覆盖父类的getInterest方法 &
72、#160; 空白处4 return getBalance() * 0.0036; public class Test public static void main(String args) &
73、#160; 空白处5 /调用Account类的getInterest方法 double b = acc.getInterest(); &
74、#160; System.out.println(b); (1). 下列选项中,能填入空白处1的代码是( ) A. public Account(String idCard, double balance) this.idCard = idCard; this.balance = balance; B. public Accou
75、nt(String idCard, double balance) idCard = idCard; balance = balance; C. public void Account(String idCard, double balance) this.idCard = idCard; &
76、#160; this.balance = balance; D. public void Account(String idCard, double balance) idCard = idCard; balance = balance; 正确答案:A (2). 下列选项中,能填入空白2的代码是(
77、; ) A. public double getBalance() return balance; public void setBalance(double balance) this.balance = balance; B. public double getbalance() return balance; public void
78、setBalance(double balance) this.balance = balance; C. public double getbalance() return balance; public void setbalance(double balance) this.balance = balance; D. public double getBalance()
79、; return balance; public void setbalance(double balance) this.balance = balance; 正确答案:A (3). 下列选项中,能填入空白处3的代码是( ) A. this(name, balance); B. Account (name, balance); C. SavingAccount(name, balance); D. super(name, b
80、alance); 正确答案:D (4). 下列选项中,能填入空白处4的代码是( ) A. public abstract double getInterest() B. public double getInterest() C. protected abstract double getInterest() D. protected double getInterest() 正确答案:B (5). 下列选项中,能填入空白处5的代码是( ) A. SavingAccount acc = new Account("102323232", 40000); B. SavingAccount acc = new SavingAccount ("102323232", 40000); C. Account acc = new Sa
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 深圳市劳务员考试题库及答案
- 人卫技师考试题库及答案
- 辅警职责培训课件
- 辅警作风建设培训课件
- 护理对医疗质量改进的贡献
- 2026年深圳中考语文文言文翻译专项试卷(附答案可下载)
- 2026年深圳中考英语临考冲刺押题试卷(附答案可下载)
- 2026年深圳中考物理易混考点辨析试卷(附答案可下载)
- 2026年深圳中考生物专题整合训练试卷(附答案可下载)
- 2026年深圳中考生物名师原创预测试卷(附答案可下载)
- 半导体semi F81 中文版
- DBJ50-T-405-2021城市道路占道施工作业交通组织设计标准
- 急性肾衰竭的临床表现
- 设计质量、进度、保密等保证措施
- 建筑工程岗前实践报告1500字
- 甲状腺手术甲状旁腺保护
- 2026年全年日历表带农历(A4可编辑可直接打印)预留备注位置
- 重庆市沙坪坝区南开中学校2022-2023学年七年级上学期期末地理试题
- 小学语文五年下册《两茎灯草》说课稿(附教学反思、板书)课件
- 曼娜回忆录的小说全文
- 饮食与心理健康:食物对情绪的影响
评论
0/150
提交评论