SUN认证Java2程序员考试(SCJP) 试题解析(2)

合集下载

国家二级(JAVA)机试模拟试卷2(题后含答案及解析)

国家二级(JAVA)机试模拟试卷2(题后含答案及解析)

国家二级(JA V A)机试模拟试卷2(题后含答案及解析) 题型有:1. 选择题 2. 基本操作题 3. 简单应用题 4. 综合应用题选择题1.下列代表十六进制整数的是( )。

A.0123B.1900C.fa00D.0xa2正确答案:D解析:本题考查Java语言中的整型常量。

整型常量有三种书写格式:十进制整数,如123,-30,365;八进制整数,以0开头,如011表示十进制的9;十六进制整数:以0x或0X开头,如0X123表示十进制数291。

由此可见,选项D表示的是十六进制整数,选项C不是整数形式,选项B是十进制整数,选项A是八进制整数,只有选项D为本题正确选项。

2.自定义的异常类可从( )类继承。

A.ErrorB.AWTErrorC.VirtualMachineErrorD.Exception及其子集正确答案:D解析:Java语言中Throwable类分为Error和Exception两个子类。

自定义的异常类是从Exception及其子集类继承的。

3.结构化分析方法是面向( )的自顶向下逐步求精进行需求分析的方法。

A.对象B.数据结构C.数据流D.目标正确答案:C解析:结构化分析方法是面向数据流进行需求分析的方法,采用自顶向下、逐层分解、建立系统的处理流程。

4.已知一个有序线性表为(13,18,24,35,47,50,62,83,90,115,134),当用二分法查找值为90的元素时,查找成功的比较次数为()。

A.1B.2C.3D.9正确答案:B解析:根据二分法查找需要两次:首先将90与表中间的元素50进行比较,由于90大于50,所以在线性表的后半部分查找;第二次比较的元素是后半部分的中间元素,即90,这时两者相等,即查找成功。

5.有下列二叉树,对此二叉树进行后序遍历的结果为()。

A.ACBEDGFHB.GDBHEFCAC.HGFEDCBAD.ABCDEFGH正确答案:B解析:对二叉树的后序遍历是指:先访问左子树,然后访问右子树,最后访问根结点,并且在访问其左、右子树时先访问其左、右子树,最后访问根结点。

java二级考试试题及答案

java二级考试试题及答案

java二级考试试题及答案Java是一门广泛应用于软件开发领域的编程语言。

对于想要进一步提升自己的Java编程能力的人来说,参加Java二级考试是一个很好的机会。

本文将介绍一些常见的Java二级考试试题及其答案,希望对准备参加这个考试的人有所帮助。

1. 试题一:什么是Java中的多态性?请举一个示例说明。

答案:Java中的多态性是指同一个方法可以根据不同的对象调用不同的实现。

通过继承和接口的方式,一个父类或接口可以有多个不同的子类实现。

例如,有一个父类Animal,有两个子类Dog和Cat,它们都重写了父类的eat()方法。

当我们调用eat()方法时,可以根据具体的对象类型调用对应的实现,即可以调用Dog的eat()方法或Cat的eat()方法。

2. 试题二:Java中的异常处理机制是什么?请举一个示例说明。

答案:Java中的异常处理机制是通过try-catch-finally语句块来实现的。

当可能发生异常的代码块被包含在try块中时,如果发生异常,程序会跳转到对应的catch块进行异常处理。

finally块中的代码无论是否发生异常都会被执行。

例如,当我们读取一个文件时,可能会发生文件不存在的异常。

我们可以在try块中打开文件,如果发生异常,则在catch块中进行异常处理,最后在finally块中关闭文件。

3. 试题三:什么是Java中的线程?请举一个示例说明如何创建和启动一个线程。

答案:Java中的线程是指程序中独立执行的一段代码。

通过创建线程,我们可以同时执行多个任务,提高程序的效率。

可以通过继承Thread类或实现Runnable接口来创建线程。

例如,我们可以创建一个继承Thread类的MyThread类,重写run()方法,在run()方法中定义线程要执行的任务。

然后,我们可以通过创建MyThread对象并调用start()方法来启动线程。

4. 试题四:Java中的集合框架有哪些?请列举并简要说明各个集合类的特点。

全国计算机等级考试二级Java题型解析

全国计算机等级考试二级Java题型解析

全国计算机等级考试二级Java题型解析全国计算机等级考试二级 Java 是许多计算机学习者和从业者都关注的一项考试。

它旨在检验考生对Java 编程语言的掌握程度和运用能力。

了解其题型对于备考至关重要。

接下来,让我们详细解析一下这些题型。

首先是选择题。

这部分通常涵盖了 Java 语言的基础知识,包括数据类型、变量与常量、运算符、控制流语句(如ifelse、for、while 等)、数组、字符串处理、面向对象编程的概念(类、对象、封装、继承、多态)、异常处理等。

选择题的特点是知识点覆盖面广,但每个题目考查的内容相对较浅。

在做选择题时,考生需要对 Java 的基本概念有清晰的理解。

例如,对于数据类型,要清楚每种数据类型的取值范围和使用场景;对于控制流语句,要能准确判断程序的执行流程;对于面向对象编程的概念,要理解各种特性的含义和作用。

其次是填空题。

这部分主要考查考生对代码片段的理解和补充能力。

题目可能会给出一段不完整的 Java 代码,要求考生根据上下文和相关知识点,填写缺失的部分,使代码能够正确运行并实现特定的功能。

填空题往往会集中在一些常见的语法结构和算法上。

比如,要求填写循环条件、方法的参数或返回值、对象的属性赋值等。

考生在做这类题目时,需要仔细阅读题目中的代码,分析其逻辑和功能需求,然后运用所学知识进行准确填写。

接下来是程序改错题。

这类题型会给出一段存在错误的 Java 程序代码,考生需要找出其中的错误并进行修改。

错误可能包括语法错误、逻辑错误、运行时错误等。

对于语法错误,常见的有标点符号使用不当、关键字拼写错误、变量未声明或声明错误等。

逻辑错误则可能是算法设计不合理、条件判断错误等。

运行时错误可能是数组越界、空指针引用等。

考生在解答时,需要逐行审查代码,结合编译错误提示和自己的逻辑分析,找出并改正错误。

然后是程序设计题。

这是考试中比较具有挑战性的部分,要求考生根据给定的问题描述,独立设计并编写完整的 Java 程序来解决问题。

SUN JAVA程序员和开发员(SCJD)认证

SUN JAVA程序员和开发员(SCJD)认证

SUN JAVA程序员和开发员(SCJD)认证SUNJAVA程序员和开发员(SCJD)认证java程序员的认证SunCertifiedJAVAProgrammer(SCJP) 课程:SL-275JAVA语言编程本课程使学员掌握如何使用标准JAVADevelopmentKit,V1.1(JDK)开发应用程序和applets。

在本课程中您将学会JAVA语言的语法。

如何使用JAVA来创建图形用户接口(GUI),事件处理机制,例外处理,通过设计与开发各种JAVA程序来获得实际的编程经验.您也将学到文件输入/输出(I/O)、多线程和网络的知识.。

本课程适用于熟悉C或C++的编程人员,也适用于想参加SunJAVA认证考试的学员。

预备知识:学习本课程之前必须具备以下能力能够编译C或C++程序或者已经参加过SL-110课程;能够创建和编译简单的程序;使用WWW(Worldwideweb)浏览器,如:Netscape;能够使用vi或者OpenWindows的文件编辑器;使用基本UNIX的命令。

课程学习完成后,将具备以下能力:使用JAVA编程语言创建JAVA应用程序和applets定义和描述垃圾搜集,安全性和JAVA虚拟机(JVM)描述和使用JAVA语言面向对象的特点开发图形用户接口(GUI),利用JAVA支持的多种布局管理描述和使用JAVA1.1的事件处理模式使用JAVA语言的鼠标输入,文本,窗口和菜单窗使用JAVA的'例外处理来控制程序执行和定义用户自己的例外事件使用JAVA语言的先进的面向对象特点,包括方法重载,方法覆盖,抽象类,接口等等实现文件的输入/输出(I/O) 使用JAVA语言内在的线程模式来控制多线程使用JAVA的Sockets机制进行网络通信参加Java程序员认证考试:java程序员认证考试考试号为310-025。

Java程序员的认证考试以Sun公司的SL-275英文原版教材为标准,需要掌握并作为考试内容的知识点有:声明和权限控制,流控制和异常处理,垃圾回收机制,基本语法,操作数和符号,重载、覆盖、运行类型和面向对象,线程等;此外,还有java.awt、ng、java.util、java.io包中的常用类等。

Sun认证Java程序员SCJP考试

Sun认证Java程序员SCJP考试

Sun认证Java程序员SCJP考试Sun认证Java程序员(SCJP)考试Sun Microsystems在行业中被认为是同行中最具创造性的企业之一,它想尝试新的软件方式和定价模式等等。

下面是店铺整理的关于Sun认证Java程序员(SCJP)考试,欢迎对大家参考!Java程序员(SCJP)考试科目简介考试方式:全英文试题,以电脑作答,在授权的Prometric考试中心参加考试考试科目:Sun Certified Programmer for Java 2 Platform 1.2 考试编号:310-025考试题型:59道选择题及简答题及格标准:答对61%(36题)以上时限:120分钟费用:1500元考试科目:Sun Certified Programmer for Java 2 Platform 1.4 考试编号:310-035考试题型:59道选择题及简答题及格标准:答对61%(36题)以上时限:120分钟费用:1500元Java程序员(SCJP)考试科目的区别SCJP的四个科目310-025、310-035、310-055、310-056的区别如下:Sun Certified Programmer for Java 2 Platform 1.2(310-025)表明你掌握了JDK1.2的'知识。

Sun Certified Programmer for Java 2 Platform 1.4(310-035)表明你掌握了JDK1.4的知识。

Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0(310-055)表明你掌握了JDK1.5的知识。

Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0 Upgrade Exam(310-056)是从JDK1.2或JDK1.4升级到JDK1.5的考试。

二级Java语言程序设计测试卷试题(含答案解析)

二级Java语言程序设计测试卷试题(含答案解析)

二级Java语言程序设计测试卷(100分)本卷考察对Java的程序设计,共40题,满分为100分。

1、1.Java程序的并发机制是()。

【单选题】(2.5分)A.多线程B.多接口C.多平台D.多态性正确答案: A2、2.下列运算符中,优先级最高的是()。

【单选题】(2.5分)A.++B.+C.*D.正确答案: A3、在一个线程中调用下列方法,不会改变该线程运行状态的是()。

【单选题】(2.5分)A.yield方法B.另一个线程的join方法C.sleep方法D.一个对象的notify方法正确答案: B4、面向对象的四个主要特性是()。

【单选题】(2.5分)A.继承性、多态性、可靠性、可维护性B.抽象性、封装性、正确性、高效性C.抽象性、封装性、继承性、多态性D.抽象性、继承性、高效性、可维护性正确答案: C5、下列表达式中,类型可以作为int型的是()。

【单选题】(2.5分)A.“abc”+“efg”B.“abc”+‘efg’C.‘a’+‘b’D.3+“4”正确答案: C6、8.下列程序的输出结果是( )。

public class Test {public static void main(String[] args){ int[] array = { 2, 4, 6, 8, 10 };int size = 6;int result = -1;try {for (int i = 0; i size result == -1;)if (array[i] == 20)result = i;} catch (ArithmeticException e){ System.out.println(Catch---1);}catch(ArrayIndexOutOfBoundsException e){ System.out.println(Catch---2);} catch (Exceptione){ System.out.println(Catch---3);}}} 【单选题】(2.5分)A.Catch---1B.Catch---2C.Catch---3D.以上都不对正确答案: D7、用于设置组件大小的方法是()。

JAVA认证历年真题_SCJP考试真题和解析

JAVA认证历年真题_SCJP考试真题和解析

JAVA认证历年真题:SCJP考试真题和解析[2]1. Which of the following range of short is correct?A. -27 -- 27-1B. 0 -- 216-1C. ?215 -- 215-1D. ?231 -- 231-1翻译下面哪些是short型的取值范围。

答案答案C解析解析短整型的数据类型的长度是16 bits,有符号。

另外需要说明的是java中所有的整(Integral)数(包括byte,short,int,long)全是有符号的。

2. Which declarations of identifiers are legal?A. $personsB. TwoUsersC. *pointD. thisE. _endline翻译下面哪些是合法的标识符。

翻译下面哪些是合法的标识符。

答案答案A,B,E解析解析Java的标识符可以以一个Unicode字符,下滑线(_),美元符($)开始,后续字符可以是前面的符号和数字,没有长度限制,大小写敏感,不能是保留字。

3. Which statement of assigning a long type variable to a hexadecimal value is correct?A. long number = 345L;B. long number = 0345;C. long number = 0345L;D. long number = 0x345L翻译哪些是将一个十六进制值赋值给一个long型变量。

答案答案D解析十六进制数以0x开头,long型数以L(大小写均可,一般使用大写,因为小写的l和数字1不易解析区分)。

4.Which of the following fragments might cause errors?A. String s = "Gone with the wind";String t = " good ";String k = s + t;B. String s = "Gone with the wind";String t;t = s[3] + "one";C. String s = "Gone with the wind";String standard = s.toUpperCase();D. String s = "home directory";String t = s - "directory";翻译下面的哪些程序片断可能导致错误。

SCJP认证考试题库2

SCJP认证考试题库2

SCJP认证考试题库2What is the result?A. n ullB. zeroC. s omeD. C ompilation failsE. An exception is thrown at runtimeAnswer: ( D )13行会报错,应在15行使用else if 参考大纲:流程控制QUESTION 63Given the exhibit:What is the result?A. testB. ExceptionC. Compilation failsD. NullPointerExceptionAnswer: ( C )18行出错,应该先catch子异常,再catch Exception;13行把args赋null ,14行会报NullPointerException如果没有第13行运行时14行会报ArrayIndexOutOfBoundsException异常。

参考大纲:异常处理QUESTION 64Given the exhibit:What is the result?A. Compilation failsB. aAaA aAa AAaa AaAC. AAaa AaA aAa aAaAD. AaA AAaa aAaA aAaE. aAa AaA aAaA AAaaF. An exception is thrown at runtimeAnswer: ( C )第10行将对strings这个集合做自然排序(ASCII小到大,一个一个比较)Collections.sort(List list) 对list进行排序,对set 不能排序!List里可以放对象,所以当list里面存放的是对象的时候就不能用Collections.sort(List list)去排序了。

因为JVM不知道用什么规则去排序!!只有把对象类实现Comparable接口,然后改写compareTo()参考大纲:集合QUESTION 65Given the exhibit:What is the result?A. 0B. 1C. 2D. 3E. 4F. Compilation fails.G. An exception is thrown at runtimeAnswer: ( D )Set中存放的元素是无序不重复的。

2022年历年计算机等级考试二级Java语言程序设计试题及答案分解

2022年历年计算机等级考试二级Java语言程序设计试题及答案分解

历年全国计算机等级考试二级Java语言程序设计试题及答案一、选择题(每题1分,共40小题,共40分)1.下列论述中对旳旳是( )。

A.一种算法旳空间复杂度大,则其时间复杂度必然大B.一种算法旳空间复杂度大,则其时间复杂度必然小C.一种算法旳时间复杂度大,则其空间复杂度必然小D.上述3种说法都不对D。

【解析】算法旳时间复杂度和空间复杂度是从不一样旳角度来衡量算法旳执行状况旳,它们之间没有内在联络。

2.开发软件时对提高开发人员工作效率至关重要旳是( )。

A.操作系统旳资源管理功能B.先进旳软件开发工具和环境C.程序员旳数量D.计算机旳并行处理能力B。

【解析】先进旳软件开发工具和环境对提高开发人员工作效率是至关重要旳。

3.程序设计语言旳基本成分是数据成分、运算成分、控制成分和( )。

A.对象成分B.变量成分C.语句成分D.传播成分D。

【解析】程序设计语言旳基本成分有:数据成分,用于描述程序所波及旳数据;运算成分,用于描述程序中所包括旳运算;控制成分,用于描述程序中所包括旳控制;传播成分,用于体现程序中数据旳传播。

4.对长度为n旳线性表进行次序查找,在最坏状况下需要比较旳次数为( )。

A.125B.n/2C.nD.n+lC。

【解析】对线性表进行次序查找时,从表中旳第一种元素开始,将给定旳值与表中逐一元素旳关键字进行比较,直到两者相符,查找到所要找旳元素为止。

在最坏状况下,要查找旳元素是表旳最终一种元素或查找失败,这两种状况都需要将这个元素与表中旳所有元素进行比较,因此比较次数为n。

5.有下列二叉树,对此二叉树前序遍历旳成果为( )。

A.XZCYABB.XYZABCC.XYABCZD.XYAZBCD。

【解析】对二叉树旳前序遍历是指:先访问根结点,然后访问左子树,最终访问右子树,并且,在访问左、右子树时,先访问根结点,再依次访问其左、右子树。

6.下列论述中对旳旳是( )。

A.在面向对象旳程序设计中,各个对象之间具有亲密旳关系B.在面向对象旳程序设计中,各个对象都是公用旳C.在面向对象旳程序设计中,各个对象之间相对独立,互相依赖性小D.上述3种说法都不对C。

SUN公司SCJP题库讲解学习

SUN公司SCJP题库讲解学习

S U N公司S C J P题库yModule 1-JAVA 基础一、选择题:Question 1Given:35. String #name = "Jane Doe";36. int $age=24;37. Double _height = 123.5;38. double ~temp = 37.5;Which two are true? (Choose two.)A. Line 35 will not compile.B. Line 36 will not compile.C. Line 37 will not compile.D. Line 38 will not compile.Answer: AD 标识符以字母,下划线,或者$开始Question 2Given:11. public class Test {12. public static void main(String [] args) {13. int x =5;14. boolean b1 = true;15. boolean b2 = false;16.17.if((x==4) && !b2)18. System.out.print("l ");19. System.out.print("2 ");20. if ((b2 = true) && b1)21. System.out.print("3");22. }23. }What is the result?A. 2B. 3C. 1 2D. 2 3E. 1 2 3F. Compilation fails.G. An exceptional is thrown at runtime. Answer: D 注意20行,=为赋值,不要被骗Question 3Given:42. public class ClassA {43. public int getValue() {44. int value=0;45. boolean setting = true;46. String title="Hello";47. if (value || (setting && title == "Hello")) { return 1; }48. if (value == 1 & title.equals("Hello")) { return 2; }49. }50. }And:70. ClassA a = new ClassA();71. a.getValue();What is the result?A. 1B. 2C. Compilation fails.D. The code runs with no output.E. An exception is thrown at runtime.Answer: C 编译不通过,47行value为int类型不是boolean Question 4Given:11. public void testIfA() {12. if(testIfB("True")) {13. System.out.println("True");14. } else {15. System.out.println("Not true");16. }17. }18. public Boolean testIfB(String str) {19. return Boolean.valueOf(str);20. }What is the result when method testIfA is invoked?A. TrueB. Not trueC. An exception is thrown at runtime.D. Compilation fails because of an error at line 12.E. Compilation fails because of an error at line 19. Answer: A 19行,如果str为true则返回ture,否则返回false Question 5Given:11. public static void main(String[] args) {12. Integer i = new Integer(1) + new Integer(2);13. switch(i) {14. case 3: System.out.println("three"); break;15. default: System.out.println("other"); break;16. }17. }What is the result?A. threeB. otherC. An exception is thrown at runtime.D. Compilation fails because of an error on line 12.E. Compilation fails because of an error on line 13.F. Compilation fails because of an error on line 15. Answer: A 就是两个Integer类型相加Question 6Given:11. public static void main(String[] args) {12. String str = "null";13. if (str == null) {14. System.out.println("null");15. } else (str.length() == 0) {16. System.out.println("zero");17. } else {18. System.out.println("some");19. }20. }‘What is the result?A. nullB. zeroC. someD. Compilation fails.E. An exception is thrown at runtime.Answer: D 这题真恶心 15行少个ifQuestion 7Given:10.int x=0;11.int y=10;12. do {l3. y--;14. ++x;15. } while (x < 5);16. System.out.print(x + "," + y);What is the result?A. 5,6B. 5,5C. 6,5D. 6,6Answer: B (91,82,73,64,55)没啥争议Question 8Given:25.int x=12;26. while (x < 10) {27. x--;28. }29. System.out.print(x);What is the result?A. 0B. 10C. 12D. Line 29 will never be reached.Answer: C 12>10,所以直接跳出循环,输出x=12 Question 9Given:35. int x= 10;36. do {37. x--;38. } while(x< 10);How many times will line 37 be executed?A. ten timesB. zero timesC. one to me timesD. more than ten timesAnswer: D 死循环Question 10Given:11. public static void main(String[] args) {12. for (int i=0;i<= 10;i++){13. if( i>6) break;14. }15. System.out.println(i);16. }What is the result?A. 6B. 7C. 10D. 11E. Compilation fails.F. An exception is thrown at runtime. Answer: E 15行i超出了作用域Question 11Given:55. int []x= {1, 2,3,4, 5};56. int y[] =x;57. System.out.println(y[2]);Which is true?A. Line 57 will print the value 2.B. Line 57 will print the value 3.C. Compilation will fail because of an error in line 55.D. Compilation will fail because of an error in line 56. Answer: B 没争议,考察数组下标是从0开始Question 12Which two code fragments(片段) correctly(正确) create and initialize a static array of int elements? (Choose two.)A. static final int[] a = { 100,200 };B. static final int[] a;static { a=new int[2]; a[0]=100; a[1]=200; }C. static final int[] a = new int[2] { 100,200 };D. static final int[] a;static void init() { a = new int[3]; a[0]=100; a[1]=200; } Answer: AB c不能指定长度,d不能在init方法中赋值,要么在static 代码块中Question 13Given:11. public static void main(String[] args) {12. Object obj = new int[] { 1,2,3 };13. int[] someArray = (int[])obj;14. for (int i: someArray) System.out.print(i +" ")15. }‘What is the result?A. 1 2 3B. Compilation fails because of an error in line 12.C. Compilation fails because of an error in line 13.D. Compilation fails because of an error in line 14.E. A ClassCastException is thrown at runtime.Answer: A 没争议,foeach循环遍历数组Question 14Given:11. String[] elements = { "for", "tea", "too" };12. String first = (elements.length > 0)? elements[0] : null;What is the result?A. Compilation fails.B. An exception is thrown at runtime.C. The variable first is set to null.D. The variable first is set to elements[0].Answer: DQuestion 15Given:10. public class Bar {11.static void foo(int...x) {12. // insert code here13. }14. }Which two code fragments, inserted independently(独立的) at line 12, will allow the class to compile? (Choose two.)A. foreach(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(x[i]);Answer: BD x相当于一个数组,a明显错没有foreach,c中x没有hadNext方法Question 16A programmer(程序员) needs to create a logging method that can accept(接受) an arbitrary(随意任意) number of arguments. For example, it may be called in theseways:logIt("log message 1 ");logIt("log message2”,”log message3");logIt("log message4", "log message5", "log message6");Which declaration(说明) satisfies(符合) this requirement(需求)?A. public void logIt(String * msgs)B. public void logIt(String [] msgs)C. public void logIt(String... msgs)D. public void logIt(String msg1, String msg2, String msg3) Answer: C 可变长参数Question 171. public class A {2. public String doit(int x, int y) {3. return "a";4. }5.6. public String doit(int... vals) {7. return "b";8. }9. }Given:25. A a=new A();26. System.out.println(a.doit(4, 5));What is the result?A. Line 26 prints "a" to System.out.B. Line 26 prints "b" to System.out.C. An exception is thrown at line 26 at runtime.D. Compilation of class A will fail due to an error in line6.Answer: A 确定参数和可变长参数同时存在的时候,优先考虑确定参数的Question 18Given a file GrizzlyBear.java:1. package animals.mammals;2.3. public class GrizzlyBear extends Bear {4. void hunt() {5. Salmon s = findSalmon();6. s.consume();7. }8. }and another file, Salmon.java:1. package animals.fish;2.3. public class Salmon extends Fish {4. void consume() { /* do stuff */ }5. }Assume(假定) both classes are defined in the correct directories for theft packages, and that the Mammal class correctly defines the findSalmon() method. Which two changes allow this code to compile correctly? (Choose two.)A. add public to the start of line 4 in Salmon.javaB. add public to the start of line 4 in GrizzlyBear.javaC. add import animals.mammals.*; at line 2 in Salmon.javaD. add import animals.fish.*; at line 2 in GrizzlyBear.javaE. add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.javaF. add import animals.mammals.GrizzlyBear.*;at line 2 in Salmon.javaAnswer: AD 调用不同包下的类,要先导入,方法权限要设置成public Question 19Given:10. package com.sun.scjp;11. public class Geodetics {12. public static final double DIAMETER = 12756.32; // kilometers13. }Which two correctly access(访问) the DIAMETER member of the Geodetics class? (Choose two.)A. import com.sun.scjp.Geodetics;public class TerraCarta {public double halfway(){ return Geodetics.DIAMETER/2.0; } }B. import static com.sun.scjp.Geodetics;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }C. import static com.sun.scjp.Geodetics. *;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }D. package com.sun.scjp;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }Answer: AC b中不能静态导入类,c中静态导入类属性,正确,d访问错误很明显Question 20Given classes defined in two different files:1. package util;2. public class BitUtils {3. private static void process(byte[] b) { }4. }1. package app;2. public class SomeApp {3. public static void main(String[] args) {4. byte[] bytes = new byte[256];5. // insert code here6. }7. }What is required(必需的) at line 5 in class SomeApp to use the process methodof BitUtils?A. process(bytes);B. BitUtils.process(bytes);C. app.BitUtils.process(bytes);D. util.BitUtils.process(bytes);E. import util.BitUtils. *; process(bytes);F. SomeApp cannot use the process method in BitUtils. Answer: F 私有的,不能被访问Question 21Given a class Repetition(重复):1. package utils;2.3. public class Repetition {4. public static String twice(String s) { return s + s; }5. }and given another class Demo:1. // insert code here2.3. public class Demo {4. public static void main(String[] args) {5. System.out.println(twice("pizza"));6. }7. }Which code should be inserted at line 1 of Demo.java to compile and run Demo to print “pizzapizza”?A. import utils.*;B. static import utils.*;C. import utils.Repetition.*;D. static import utils.Repetition. *;E. import utils.Repetition.twice();F. import static utils.Repetition.twice;G. static import utils.Repetition.twice;Answer: F 静态导入Question 22Given:1. package test;2.3. class Target(目标) {4. public String name = "hello";5. }What can directly(直接的) access and change the value ofthe variable(变量) name?A. any classB. only the Target classC. any class in the test packageD. any class that extends TargetAnswer: C default类型的类本包访问权限Question 23Given:11. rbo = new ReallyBigObject();12. // more code here13. rbo = null;14. /* insert code here */Which statement(语句) should be placed at line 14 tosuggest(促成) that the virtual machine(虚拟机) expend(消耗) effort(努力) toward recycling(回收) the memory used by the object rbo?A. System.gc();B. Runtime.gc();C. System.freeMemory();D. Runtime.getRuntime().growHeap();E. Runtime.getRuntime().freeMemory();Answer: A 题很简单。

编程考试二级答案解析

编程考试二级答案解析

编程考试二级答案解析1. 题目:以下哪个选项是正确的C语言函数声明?A. int myFunction(int x, int y)B. int myFunction(x, y)C. int myFunction(int x, y)D. int myFunction(int x, int y) {}解析:在C语言中,函数声明需要指明函数的返回类型、函数名以及参数列表,包括参数的类型。

选项A正确地声明了一个名为myFunction的函数,它接受两个整型参数并返回一个整型值。

选项B 缺少参数类型,选项C缺少第二个参数的类型,选项D虽然包含了函数体,但函数声明不应包含函数体。

因此,正确答案是A。

2. 题目:在Java中,以下哪个关键字用于声明一个类?A. interfaceB. classC. structD. enum解析:在Java编程语言中,关键字class用于声明一个类。

interface用于声明一个接口,struct是C++中的关键字,用于声明一个结构体,而enum用于声明一个枚举类型。

因此,正确答案是B。

3. 题目:以下哪个选项是Python中正确的列表推导式?A. [x for x in range(10)]B. [x if x % 2 == 0 for x in range(10)]C. [x for x in range(10) if x % 2 == 0]D. [x if x % 2 == 0 for x in range(10) if x > 5]解析:列表推导式是Python中快速生成列表的一种方式。

选项A是正确的列表推导式,它生成了一个包含0到9的整数列表。

选项B和D中的if语句位置不正确,它们应该放在for语句之后。

选项C也是正确的列表推导式,它生成了一个包含0到9中所有偶数的列表。

因此,正确答案是A和C。

4. 题目:在JavaScript中,以下哪个选项是正确的事件监听器语法?A. document.getElementById("myButton").onclick = function() { alert("Hello World!"); };B.document.getElementById("myButton").addEventListener("click", function() { alert("Hello World!"); });C. document.getElementById("myButton").onclick ="alert('Hello World!');";D.document.getElementById("myButton").addEventListener("click", "alert('Hello World!');");解析:在JavaScript中,添加事件监听器有两种常见的方法。

java 二级 试题及答案

java 二级 试题及答案

java 二级试题及答案Java二级试题及答案Java是一种广泛应用于软件开发领域的编程语言,掌握Java编程对于计算机专业人士来说尤为重要。

为了帮助读者更好地了解与掌握Java,本文将介绍一些常见的Java二级试题以及相应的详细答案。

第一节:基础知识题1. 什么是Java语言?它的特点是什么?Java语言是一种面向对象的程序设计语言,由Sun Microsystems公司于1995年推出。

它具有以下特点:- 简单易学:Java语法简洁明了,规范性强,相对于其他编程语言来说更容易上手。

- 面向对象:Java支持面向对象的编程风格,可以通过类和对象的概念来组织代码和数据。

- 平台无关性:Java应用程序可以在不同的操作系统上运行,因为Java程序是在Java虚拟机(JVM)上运行的。

- 安全性:Java提供了一些安全特性,如字节码验证和安全管理器,以确保程序在运行时的安全性。

- 高性能:Java通过Just-In-Time(JIT)编译器将字节码转换为本地机器码,从而提高了执行效率。

2. Java中如何实现多线程?请简要描述一下多线程同步的方法。

在Java中,可以通过继承Thread类或实现Runnable接口来创建多线程。

下面是一个使用Runnable接口的示例代码:```javapublic class MyThread implements Runnable {public void run() {// 线程执行的代码}public static void main(String[] args) {Thread thread = new Thread(new MyThread());thread.start();}}```多线程同步可以通过以下方法实现:- 使用synchronized关键字:可以用来修饰方法或代码块,确保同一时间只有一个线程可以访问被修饰的代码,从而避免竞态条件和数据不一致的问题。

国家二级(JAVA)机试模拟试卷2(题后含答案及解析)_0

国家二级(JAVA)机试模拟试卷2(题后含答案及解析)_0

国家二级(JA V A)机试模拟试卷2(题后含答案及解析) 题型有:1. 基本操作题 2. 简单应用题 3. 综合应用题基本操作题(30分)1.下列程序中,要求输出一个特定文件(这里是ex2_1.java)的相关信息,包括文件的名字,相对路径以及文件的长度。

请将程序补充完整。

程序运行结果如下:name:ex2_1.java path:ex2_1.java length:299 import java.io.*;public class ex2_1{ public static void main(String[] args) { File file2_1 = new File(“ex2_1.java”);System.out.println(“name:”+file2_1.____________ );System.out.println(“path:”+file2_1.____________ );System.out.println(“length:”+file2_1.____________ );} }正确答案:getName( )getPath( )length( )解析:本题主要考查Java文件以及Java类库中的File类的常用方法。

解题关键是熟记Java的File类的常用方法:getName( ),getPath( ),length( )等。

在本题中,这3个空分别对应填入这3个方法即可。

简单应用题(40分)2.请完成下列Java程序:创建一个下拉式菜单,菜单项包括3个CheckboxMenultem(复选框),一条分割线和一个Exit项。

要求打开或关闭复选框时,确定是哪个被切换,是开还是关,并输出它的状态;选择Exit项能够退出程序。

注意:请勿改动main( )主方法和其他已有语句内容,仅在下划线处填入适当的语句。

程序运行结果如下;import j ava. awt. *; import j ava. awt. event. *; public class ex4_2 extends Frame implements ItemListener, ActionListener{ public static void main(String[] arg) {ex4_2 obj4_2 = new ex4_2( ); } ex4_2 ( ) { super ( “ex4_2”); MenuBar mb = new MenuBar ( ); Menu m = new Menu(“Menu”); MenuItem mi;mb.add(m);CheckboxMenuItem cb;cb = new CheckboxMenuItem(“Checkl”);cb.addItemListener(this);m.add(cb);cb = new CheckboxMenuItem(“Check2”);cb.addItemListener(this);m.add(cb);cb = new CheckboxMenuItem(“Check3”);cb.addItemListener(this);m.add(cb);m.addSeparator( );m.add(mi=newMenuItem(“Exit”));mi.addActionListener(this);setMenuBar(mb);setSize(50,50);show ( ); } public void itemStateChanged(ItemEvent event)System.out.print(event.getItem( ));switch(event.getStateChange( )) {case ItemEvent.DESELECTED: System.out.println(“ DESELECTED”); break; case______________; ______________; break;} } public void actionPerformed(ActionEvent ae) if(ae.getActionCommand( ).equals(“Exit-)) System.exit(O); } } }正确答案:ItemEvent.SELECTEDSystem.out.println(“ SELECTED “)解析:本题主要考查图形用户界面以及事件监听器的使用以及case语句的使用。

计算机二级Java精选习题及答案(2)

计算机二级Java精选习题及答案(2)

计算机二级Java精选习题及答案(2)1.下列叙述中正确的是()。

A.栈是“先进先出”的线性表B.队列是“先进后出”的线性表C.循环队列是非线性结构D.有序线性表既可以采用顺序存储结构,也可以采用链式存储结构2.支持子程序调用的数据结构是()。

A.栈B.树C.队列D.二叉树3.某二叉树有5个度为2的结点,则该二叉树中的叶子结点数是()。

A.10B.8C.6D.44.下列排序方法中,最坏情况下比较次数最少的是()。

A.冒泡排序B.简单选择排序C.直接插入排序D.堆排序5.软件按功能可以分为应用软件、系统软件和支撑软件(或工具软件)。

下面属于应用软件的是()。

A.编辑程序B.操作系统C.教务管理系统D.汇编程序6.下面叙述中错误的是()。

A.软件测试的目的是发现错误并改正错误B.对被调试的程序进行“错误定位”是程序调试的必要步骤C.程序调试通常也被称为DebugD.软件测试应严格执行测试计划,排除测试的随意性7.耦合性和内聚性是对模块独立性度量的两个标准,下列叙述中正确的是()。

A.提高耦合性降低内聚性有利于提高模块的独立性B.降低耦合性提高内聚性有利于提高模块的独立性C.耦合性是指一个模块内部各个元素间彼此结合的紧密程度D.内聚性是指模块闻互相连接的紧密程度8.数据库应用系统中的核心问题是()。

A.数据库设计B.数据库系统设计C.数据库维护D.数据库管理员培训9.有两个关系R、S如下:由关系R通过运算得到关系S,则所使用的运算为()。

A.选择C.插入D.连接10.将E—R图转换为关系模式时,实体和联系都可以表示为()。

A.属性B.键C.关系D.域11.Java虚拟机(JVM)运行Java代码时,不会进行的操作是()。

A.加载代码B.校验代码C.编译代码D.执行代码12.Java程序的并发机制是()。

A.多线程C.多平台D.多态性13.在方法内部使用,代表对当前对象自身引用的关键字是()。

A.superB.ThisC.SuperD.this14.阅读下列程序publicclassVariableUse{publicstaticvoidmain(String[]args){inta;if(a==8){intb=9;System.OUt.println("a="+a):System.out.println("b="+b);}System.Out.println("a="+a):System.OUt.println("b="+b);}}该程序在编译时的结果是()。

[IT认证]sun公司认证scjp证书考题模拟试题2

[IT认证]sun公司认证scjp证书考题模拟试题2

QUESTION 1Exhibit:1.public class SimpleCalc {2.public: int value;3.public void calculate() ( value +- 7; }4 }And:1. public class HuitiCalc extends SiifcpleCalc(public void calculate() { value -* 3; ) public void 2 3 4-5678ealculate(int multiplier) { oail^ulat;supsr.calculate():value *±> multiplier:}publi3 static void iwain(String[ ] args)9. MultiCalc calculator newMultiualc();10.cailculatoi?. calculate( 2 );11.System.out printIn(°Value is: , + calculator value);12.}i*> \What is the result?A. Value is : 8B. Compilation fails.C. Value is : 12D. Value is ; -12E. The code runs with no outputF. An exception is thrown at runtime.Answer:( )QUESTION 2Given the exhibit:20 public clagg Certkiller Card (21.22private String card ID:23pnvale Iritcgi h口it,24public String ov^nerName^25.26 public void set Cardin form st i^n (String c ar dID,27. String o wne rName,28 Integer limit)(29 一this.cardLD= cardlB,30 this J wiietNdiHic —QWticiiTanie^31.thbs.limii =limit;32 }33. }Which statement is true?A. The class is fully encapsulatedB. The code demonstrates polymorphism.C. The ownerName variable breaks encapsulationD. The CardID and limit variables break polymorphismE. The setCardInformation method breaks encapsulationAnswer:( )QUESTION 3Given the exhibit:11 class Animal ( public String noise () ( return "peep"))12.chfs Dog extends Animal (13.public String noist () { return、角clT; }14}15Cat expends A DIHI^I(16.public String noise () { return "mo耻”;)17.} b ■ h h ri30Animal animal =new Dog ();31.Cat cal = (Cat) animal;32.System out.pnntln (Car Noise () )FWhat is the result?A. peepB. barkC. meowD. Compilation fails.E. An exception is thrown at runtimeAnswer:( )QUESTION 4Exhibit:1public class Car {2private int vheelCount;3private String vin (4pub 1 c Car (Str ing vm ) {5this vin = vin:6“this vheelCount - 4;7. )R public Stringextend() {3 return "zoom ^oom *.10- }11public St以ng getlnfo() (12return "WIN: " + vin + * vheels * + vheelCcunt13.)14.}And1public class MeGo ewtends Oar (2public MeGo(String vin)(3this vkeeiCount - 3;4- )5 }What two must the programmer do to oerrect the compilation errors?A. insert a call to this ( ) in the Car CONSTRUCTORB. insert a call to this ( ) in the MeGo constructorC. insert a call to super ( ) in the MeGo constructorD. insert a call to super (vin) in the MeGo constructorE. change the wheel Count variable in CAR TO PROTECTEDF. CHANGE LINE 3 IN THE MeGo class to super wheel Count =3;Answer:( )QUESTION 5Given the exhibit:10interface A { public int gtValue ();)11class B implements A {12.PUBLIC INT GETvALUE () return 1;)B )14.class C extends B (15.// insert code here16’)What three cade inserted mdh Lduallv at line 15. niake use ofWhat three code fragments inserted individually at line 15, make use of polymorphism? (choose three)A. public void add (C c) ( c.getValue ( ); }B. public void add (B b) ( b.getValue ( ); }C. public void add (A a) ( a.getValue ( ); }D. public void add (A a, B b) ( a.getValue ( ); }E. public void add (C c1 C c2) { c1.getV alue ( ); }Answer:( )QUESTION 6Given the exhibit:11 certkilter = new Rs ally Big Object ()t12.// more coce here13.cerftiller = null;14./x insert code here*/Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime ( ) growHeap ()E. Runtime.getRuntime ( ) free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )A. public void add (C c) { c.getValue ();}B. public void add (B b) { b.getValue ();}C. public void add (A a) { a.getValue ();}D. public void add (A a, B b) { a.getValue ();}E. public void add (C c1 C c2) { c1 .getV alue ();}Answer:( )QUESTION 6Given the exhibit:Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ?A. System.gc ()B. Runtime. Gc ()C. System.freeMemory ()D. Runtime.getRuntime () growHeap ()E. Runtime.getRuntime () free Memory ()Answer:( )。

scjp认证试题及答案

scjp认证试题及答案

scjp认证试题及答案1. 以下哪个选项是Java中声明接口的正确语法?A. interface MyInterface { }B. public interface MyInterface { }C. abstract class MyInterface { }D. class MyInterface { }答案:B2. 在Java中,以下哪个关键字用于定义一个方法?A. classB. interfaceC. methodD. function答案:B3. Java程序中的main方法的返回类型是什么?A. voidB. intC. StringD. boolean答案:B4. 以下哪个选项不是Java中的访问修饰符?A. publicB. protectedC. privateD. static答案:D5. 在Java中,以下哪个关键字用于捕获异常?A. tryB. catchC. throwD. finally答案:B6. Java中,以下哪个关键字用于定义一个类?A. classB. interfaceC. structD. type答案:A7. 在Java中,以下哪个关键字用于强制类型转换?A. castB. convertC. typeD. (Type)答案:D8. Java中,以下哪个关键字用于声明一个变量?A. varB. letC. defineD. declare答案:A9. 在Java中,以下哪个关键字用于实现接口?A. implementsB. extendsC. inheritD. override答案:A10. Java中,以下哪个关键字用于继承一个类?A. extendsB. implementsC. inheritD. override答案:A11. 在Java中,以下哪个关键字用于定义一个枚举?A. enumB. listC. setD. map答案:A12. Java中,以下哪个关键字用于定义一个方法的重载?A. overloadB. overloadsC. overloadingD. overload答案:D13. 在Java中,以下哪个关键字用于定义一个方法的重写?A. overrideB. extendsC. implementsD. overload答案:A14. Java中,以下哪个关键字用于声明一个静态方法?A. staticB. publicC. privateD. protected答案:A15. 在Java中,以下哪个关键字用于声明一个静态变量?A. staticB. finalC. constD. volatile答案:A。

国家计算机二级试题及答案详解

国家计算机二级试题及答案详解

国家计算机二级试题及答案详解一、JAVA知识点1. 下列关于Java语言特点的说法中,正确的是()A. 完全面向对象B. 支持继承和多态C. 自动内存管理D. 所有答案都正确解析:D。

Java语言是一种完全面向对象的编程语言,支持继承和多态,并且具有自动内存管理的特点。

因此,选项D是正确的。

2. 下列哪个关键字可以用于定义一个类的成员方法不能被继承的特性?A. abstractB. extendC. finalD. super解析:C。

关键字final可以用于定义一个类的成员方法不能被继承的特性,选项C是正确的。

3. 在Java中,下列关于接口的说法中,正确的是()A. 接口可以直接实例化B. 一个类可以实现多个接口C. 接口可以包含成员变量D. 接口中的方法可以有多个实现解析:B。

一个类可以实现多个接口是Java中的特点,因此选项B 是正确的。

4. 下面哪个选项描述了Java中的多态性?A. 一个对象可以同时引用多个类B. 子类可以继承父类的属性和方法C. 一个方法可以有多个不同的实现方式D. 程序可以同时运行多个过程解析:C。

Java中的多态性指的是一个方法可以有多种不同的实现方式,因此选项C是正确的。

二、数据库知识点1. 关系型数据库中,以下哪个是用于添加数据的SQL语句?A. SELECTB. UPDATEC. DELETED. INSERT解析:D。

用于添加数据的SQL语句是INSERT,因此选项D是正确的。

2. 下列说法中,关于数据库范式的说法正确的是()A. 范式越高,数据的冗余越多B. 范式越低,数据的冗余越少C. 范式与数据库性能没有关系D. 范式可以提高数据库的可扩展性解析:B。

范式越低,数据的冗余越少,因此选项B是正确的。

3. 数据库中,以下哪个操作是用于删除表中的某一列?A. ALTER TABLEB. REMOVE COLUMNC. DROP COLUMND. DELETE COLUMN解析:C。

SUN认证Java2程序员考试(SCJP)试题解析

SUN认证Java2程序员考试(SCJP)试题解析

SUN认证Java2程序员考试(SCJP)试题解析
佚名
【期刊名称】《软件》
【年(卷),期】2003(000)012
【摘要】前言无论你是个新手.还是程序设计方面的专家.你都会惊异于Sun公司、Java的无穷魅力。

Java带给你的并不仅仅是面向对象、开放、平台无关、易用、安全和“Write once,run anywhere“等软件开发方面的优势。

更重要的一点是。

它提供了一种新颖的表达思想的方式。

一种全新的思维模式。

随着待解决问题的规模不断膨胀.Java彻底的面向对象思想的灵活性就会凸现出来。

毋庸置疑、Java是你开发大型软件时最得心应手的利器或是你转行IT的入门首选。

【总页数】5页(P83-87)
【正文语种】中文
【中图分类】TP311.1
【相关文献】
1.2003年全国程序员考试上午试题评析 [J], 张锦祥
2.程序员资格(水平)考试题例分析 [J], 包红香
3.浅析网络程序员考试中的JavaScript试题 [J], 张锦祥
4."节约型社会"引领"节约型"中考试题——近期节能型中考试题解析 [J], 朱云
5.“节约型社会”引领“节约型”中考试题——近期节能型中考试题解析 [J], 朱云
因版权原因,仅展示原文概要,查看原文内容请购买。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

SUN认证Java2程序员考试(SCJP) 试题解析(2)SUN认证Java2程序员考试(SCJP) 试题解析(2) which of the following lines of code will pile without error?
a.
int i=0;
if (i) {
system.out.println(“hi”);
}
b.
boolean b=true;
boolean b2=true;
if(b==b2) {
system.out.println(“so true”); }
c.
int i=1;
int j=2;
if(i==1|| j==2)
system.out.println(“ok”);
d.
int i=1;
int j=2;
if (i==1 &| j==2)
system.out.println(“ok”);
解答:b, c
点评:选项a错,因为if语句后需要一个boolean类型的表达式。

逻辑操作有^、&、| 和 &&、||,但是“&|”是非法的,所以选项d
不正确。

例题5:
which two demonstrate a "has a" relationship? (choose two) a. public interface person { }
public class employee extends person{ }
b. public interface shape { }
public interface rectandle extends shape { }
c. public interface colorable { }
public class shape implements colorable
{ }
d. public class species{ }
public class animal{private species species;}
e. interface ponent{ }
class container implements ponent{
private ponent[] children;
}
解答:d, e
点评:在java中代码重用有两种可能的方式,即组合(“has a”关系)和继承(“is a”关系)。

“has a”关系是通过定义类的属性的方式实现的;而“is a”关系是通过类继承实现的。

本例
中选项a、b、c体现了“is a”关系;选项d、e体现了“has a”关系。

例题6:
which two statements are true for the class
java.util.treeset? (choose two)
a. the elements in the collection are ordered.
b. the collection is guaranteed to be immutable.
c. the elements in the collection are guaranteed to be unique.
d. the elements in the collection are aessed using a unique key.
e. the elements in the collection are guaranteed to be synchronized
解答:a, c
点评:treeset类实现了set接口。

set的特点是其中的元素惟一,选项c正确。

由于采用了树形存储方式,将元素有序地组织起来,所以选项a也正确。

例题7:
true or false: readers have methods that can read and return floats and doubles.
a. ture
b. false
解答:b
点评: reader/writer只处理unicode字符的输入输出。

float 和double可以通过stream进行i/o.
例题8:
what does the following paint() method draw?
1. public void paint(graphics g) {
2. g.drawstring(“any question”, 10, 0);
3. }
a. the string “any question?”, with its top-left corner at 10,0
b. a little squiggle ing down from the top of the ;ponent.
解答:b
模板,内容仅供参考。

相关文档
最新文档