java英文SCGP试卷2
全国计算机等级考试二级Java模拟试卷及答案
全国计算机等级考试二级Java模拟试卷及答案Java语言程序设计一、选择题(1)Java语言具有许多优点和特点,下列选项中,哪个反映了Java程序并行机制的特点?A)安全性B)多线性C)跨平台D)可移植(2)下列哪个类声明是正确的?A)abstract final class HI{···}B)abstract private move(){···}C)protected private number; D)public abstract class Car{···}(3)下列关于for循环和while循环的说法中哪个是正确的?A)while循环能实现的操作,for循环也都能实现B)while循环判断条件一般是程序结果,for循环判断条件一般是非程序结果C)两种循环任何时候都可替换D)两种循环结构中都必须有循环体,循环体不能为空(4)异常包含下列那些内容?A)程序中的语法错误B)程序的编译错误C)程序执行过程中遇到的事先没有预料到的情况D)程序事先定义好的可能出现的意外情况(5)Character流与Byte流的区别是A)每次读入的字节数不同B)前者带有缓冲,后者没有C)前者是块读写,后者是字节读写D)二者没有区别,可以互换使用(6)监听事件和处理事件A)都由Listener完成B)都由相应事件Listener处登记过的构件完成C)由Listener和构件分别完成D)由Listener和窗口分别完成(7)Applet可以做下列那些操作?A)读取客户端文件B)在客户端主机上创建新文件C)在客户端装载程序库D)读取客户端部分系统变量(8)下列哪个属于容器的构件?A)JFrame B)JButton C)JPnel D)JApplet(9)如果希望所有的控件在界面上均匀排列,应使用下列那种布局管理器?A)BoxLayout B)GridLayout C)BorderLayout D)FlowLouLayout(10)为实现多线程之间的通信,需要使用下列那种流才合适?A)Filter stream B)File stream C)Random access stream D)Pipde stream二、填空题(1)对象串行化可以很容易地扩展成支持Java对象的[1],它提供了对象从流中重建的补充方式.(2)Vector类的对象是通过capacity和capacityIncrement两个值来改变集合的容量,其中capacity表示集合最多能容纳的[2] ,capacityIncrement表示每次增加多少容量,不是一个一个增加.(3)下列程序的功能是判断某一年是否为闰年.请在横线处填入适当内容,使程序能够正确运行.import java.io.*;public class LeapYear{public static void main(String arge[])throws IOException{InputStreamReader ir;BufferdeReadwe in;ir=new InputStreamReader(System.in);in=new BufferedReader(ir);System.out.println(“输入年份是:”);String s= [3]int year=Integer.parseInt(s);if year % 4 = = 0 && year % 100! = 0 // year % 400 = = 0){System.out.println(""+year+"年是闰年.");}else{System.out.println(""+year+"年不是闰年..");}}}(4)下面程序对数组中每个元素赋值,然后按逆序输出.请在横线处填入适当内容,使程序能正常运行.import java.io.*;public class ArrayTest{public static void main(String args[]){int i;int a[] = new int[5];for(i=0;i<5;i++)a=i;for( [4] i>=0;i- -)System.out.println("a["+i+"]="a);}}(5)下列程序的功能是:输入一个姓名,程序运行后,输出“姓名Welcome you!”.例如,输入“张三Welcomeyou !”.请在下面横线处填入正确的方法名,使程序可以正确运行.import java,awt,*;import java.awt.event.*;public class welcomenYou{public static void main(String args[]){new FrameInOut();}}class FrameInOut extends Frame implements ActionListener{Label prompt;TextField input,output;Button btnn;void FramInOut(){prompt=new Label("Please input your name");input=new TextField(10);output=new TextField(25);btnn=new Button("Class");[5] (new FlowLayout());add(prompt);add(input);add(output);add(btnn);input.addActionListener(this);btnn.addActionListener(this);setSize(300.200);show();}public void actionperformed(ActionEvent e){if(e.getSource() = = input)output.setText(input.getText()+"Welcome you!");else{dispose();system.exit(0);}}}Java程序设计答案一:选择题:1-5 :B D D C C6-10:B A A B D二:填空题:(1)[1]:持续存储或持久存储(2)[2]:元素个数(3)[3]:in.readLine()(4)[4]:i=a.Length-1(5)[5]:setLayout。
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二级试题及答案一、选择题1.下列哪个选项用于创建一个类的实例?A. newB. thisC. finalD. void2.以下哪个关键字用于定义一个类的方法可以被子类重写?A. publicB. finalC. staticD. abstract3.以下哪个关键字用于定义一个类的成员变量可以被子类直接访问?A. privateB. protectedC. staticD. transient4.下列哪个选项是Java的基本数据类型?A. StringB. IntegerC. BooleanD. Double5.以下哪个选项是Java中的循环结构?A. forB. ifC. switchD. try二、填空题1. 声明一个整型变量并将其初始化为10:int num = _________ ;2. 定义一个常量并赋值为3.14:final double PI = _________ ;3. 定义一个字符串变量,并将其初始化为空串:String str =_________ ;4. 声明一个布尔变量并将其初始化为真:boolean flag = _________ ;5. 将两个整数相加并将结果赋值给一个整型变量:int sum =_________ + _________ ;三、编程题1. 编写一个Java程序,实现输入一个整数n,并输出1到n之间所有偶数的和。
示例输入:10示例输出:302. 编写一个Java程序,实现输入一个字符串,判断该字符串是否是回文串(正序和反序读都一样)。
示例输入:radar示例输出:是回文串3. 编写一个Java程序,实现输入一个整数n,并输出斐波那契数列的前n项。
示例输入:5示例输出:0 1 1 2 3四、简答题1. 什么是Java的面向对象特性?举例说明面向对象编程的好处。
2. Java中的继承和多态的概念分别是什么?它们如何实现面向对象的特性?3. Java中的异常处理机制是什么?说明try-catch-finally语句的作用和使用方法。
SUN认证Java2程序员考试(SCJP) 试题解析(2)
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”关系)。
全国计算机等级考试二级Java模拟试卷及答案
全国计算机等级考试二级Java模拟试卷及答案Java一、选择题(1)Java语言具有许多优点和特点,下列选项中,哪个反映了Java程序并行机制的特点?BA)安全性 B)多线性 C)跨平台 D)可移植(2)下列哪个类声明是正确的?DA)abstract final class HI{} B)abstract private move(){}C)protected private number; D)public abstract class Car{}(3)下列关于for循环和while循环的说法中哪个是正确的?DA)while循环能实现的操作,for循环也都能实现B)while循环判断条件一般是程序结果,for循环判断条件一般是非程序结果C)两种循环任何时候都可替换D)两种循环结构中都必须有循环体,循环体不能为空(4)异常包含下列那些内容?CA)程序中的语法错误B)程序的编译错误C)程序执行过程中遇到的事先没有预料到的情况D)程序事先定义好的可能出现的意外情况(5)Character流与Byte流的区别是CA)每次读入的字节数不同 B)前者带有缓冲,后者没有C)前者是块读写,后者是字节读写 D)二者没有区别,可以互换使用(6)在设计程序时,应采纳的原则之一是 DA.不限制goto语句的使用 B.减少或取消注解行C.程序越短越好 D.程序结构应有助于读者理解(7)程序设计语言的基本成分是数据成分、运算成分、控制成分和 DA.对象成分 B.变量成分1C.语句成分 D.传输成分(8)下列叙述中,不属于软件需求规格说明书的作用的是 DA.便于用户、开发人员进行理解和交流B.反映出用户问题的结构,可以作为软件开发工作的基础和依据C.作为确认测试和验收的依据D.便于开发人员进行需求分析(9)下列哪个选项是合法的标识符?BA.123 B._name C.class D.1first (10)下列哪个选项是Java调试器,如果编译器返回程序代码的错误,可以用它对程序进行调试? CA.java.exe B.javadoc.exe C.jdb.exe D.javaprof.exe (11)下列关于继承的哪项叙述是正确的? DA.在java中允许多重继承B.在java中一个类只能实现一个接口C.在java中一个类不能同时继承一个类和实现一个接口 D.java的单一继承使代码更可靠(12)下列哪个修饰符可以使在一个类中定义的成员变量只能被同一包中的类访问? BA.private B.无修饰符 C.public D.protected (13)给出下列代码,如何使成员变量m 被方法fun()直接访问? C class Test{private int m;public static void fun(){...}2}A.将private int m 改为protected int m B.将private int m 改为public int m C.将private int m 改为 static int m D.将private int m 改为 int m (14)已知有下列类的说明,则下列哪个语句是正确的?A public class Test{private float f = 1.0f;int m = 12;static int n=1;public static void main(String arg[]){Test t = new Test();}}A.t.f; B.this.n; C.Test.m; D.Test.f;(15)下列代码的执行结果是 A public class Test{public int aMethod(){static int i=0;i++;System.out.println(i);3}public static void main(String args[]){Test test = new Test();test.aMethod();}}A.编译错误 B.0 C.1 D.运行成功,但不输出(16)下列关于内部类的说法不正确的是CA.内部类的类名只能在定义它的类或程序段中或在表达式内部匿名使用 B.内部类可以使用它所在类的静态成员变量和实例成员变量 C.内部类不可以用abstract修饰符定义为抽象类D.内部类可作为其他类的成员,而且可访问它所在类的成员(17)顺序执行下列程序语句后,则b的值是 CString a="Hello";String b=a.substring(0,2);A.Hello B.hello C.Hel D.null (18)在oneMethod()方法运行正常的情况下,程序段将输出什么? D public void test(){try { oneMethod();System.out.println("condition 1");} catch (ArrayIndexOutOfBoundsException e){System.out.println("condition 2");} catch(Exception e)4{System.out.println("condition 3");} finally{System.out.println("finally");}}A.condition 1 B.condition 2 C.condition 3 D.condition 1finally (19)下列常见的系统定义的异常中,哪个是输入、输出异常? B A.ClassNotFoundException B.IOException C.FileNotFoundException D.UnknownHostException (20)下列哪个选项是正确计算42度(角度)的余弦值?C A.double d=Math.cos(42);B.double d=Math.cosine(42);C.double d=Math.cos(Math.toRadians(42));D.double d=Math.cos(Math.toDegrees(42));(21)下列InputStream类中哪个方法可以用于关闭流?B A.skip() B.close() C.mark() D.reset()(22)下列方法中哪个是执行线程的方法?AA.run() B.start() C.sleep() D.suspend()(23)下列关于Frame类的说法不正确的是 CA.Frame是Window类的直接子类B.Frame对象显示的效果是一个窗口C.Frame被默认初始化为可见D.Frame的默认布局管理器为BorderLayout5(24)下列Java常见事件类中哪个是鼠标事件类? C A.InputEventB.KeyEventC.MouseEventD.WindowEvent(25)在Applet的关键方法中,下列哪个方法是关闭浏览器以释放Applet占用的所有资源? DA.init()B.start()C.paint()D.destroy()(26)下列哪个是面向大型企业级用容器管理专用构件的应用平台? AA.J2EEB.J2MEC.J2SED.J2DE(27)下列哪个选项的java源文件代码片段是不正确的? BA.package testpackage;public class Test{ }B.import java.io.*;package testpackage;public class Test{ }C.import java.io.*;class Person{ }public class Test{ }D.import java.io.*;6import java.awt.*;public class Test{ }二、填空题(1)对象串行化可以很容易地扩展成支持Java对象的 [1],它提供了对象从流中重建的补充方式。
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";翻译下面的哪些程序片断可能导致错误。
java二级试题及答案
java二级试题及答案一、选择题(每题2分,共10题,共计20分)1. 下面哪个选项不是Java关键字?A. classB. packageC. finalD. import2. 下面哪种循环语句可以用于遍历数组或集合?A. forB. whileC. do-whileD. switch3. Java中的包(package)用于什么目的?A. 控制类的访问权限B. 封装类的属性和方法C. 组织类的层次结构D. 使类具有继承特性4. 在Java中,以下哪个关键字用于定义一个类的子类?A. superB. thisC. extendsD. implements5. 下面哪个选项不是Java中的访问修饰符?A. privateB. protectedC. publicD. static6. 在Java中,以下哪个方法用于启动一个新的线程?A. start()B. run()C. execute()D. launch()7. 在Java中,以下哪个异常类是所有异常的父类?A. ExceptionB. RuntimeExceptioinC. ErrorD. Throwable8. 在Java中,以下哪个关键字用于定义常量?A. varB. constC. finalD. static9. 在Java中,以下哪种集合类用于存储键值对?A. ArrayListB. HashSetC. LinkedListD. HashMap10. 下面哪个选项不是Java中的基本数据类型?A. intB. doubleC. booleanD. string二、填空题(每空2分,共5题,共计10分)1. Java中的数据类型分为两类,分别为基本数据类型和_____________。
2. Java中的三目运算符的格式是_____________。
3. 在Java中,方法的重载是指在同一个类中,方法名相同但参数类型或个数_____________的情况下可以存在多个方法。
SCJP认证考试题库2
QUESTION 61GIVEN THE EXHIBIT:Which statement is true?A. All of the assert statements are used appropriately.B. Only the assert statement on line 31 is used appropriatelyC. The assert statements on lines 29 and 31 are used appropriatelyD. The assert statements on lines 26 and 29 are used appropriatelyE. The assert statements on lines 29 and 33 are used appropriatelyF. The assert statements on lines 29 ,31and 33 are used appropriatelyG. The assert statements on lines 26,29 and 31 are used appropriately断言应该用在“你认为”你的程序不可能产生错误的地方,而且有没有启用断言,都不会影响程序的正常运行。
断言使用限制:1.不要在public方法中,用断言来检查参数的正确性;2.不要让断言语句去处理一些程序必须的流程。
原因:1.public方法会被别人调用,你不能保证他一定启用断言;如果没有启用,那么用断言来做参数的检查也就没有意义了。
所以不要用断言来检查参数,公共方法的参数一定要用代码执行检查; 2.如果用断言来控制程序执行流程,如果没有启用断言,那么程序就不能正确执行下去。
另外,断言语句不可以有任何边界效应,不要使用断言语句去修改变量和改变方法的返回值,如果这样当启动断言和不启动断言执行的结果会截然不同。
断言的使用时机:1.检查流程的不变性:在if-else switch-case 的预期结果之外可以加上断言做额外的检查。
SUN认证Java2程序员考试(SCJP) 试题解析(2)
SUN认证Java2程序员考试(SCJP) 试题解析(2)SUN认证Java2程序员考试(SCJP) 试题解析(2)SUN认证Java2程序员考试(SCJP) 试题解析(2)whichofthefollowinglinesofcodewillcompilewithouterror?a.inti=0;if(i){system.out.println( hi );}b.booleanb=true;booleanb2=true;if(b==b2){system.out.println(whichtwodemonstratea"hasa"relationship?(choosetwo)a.publicinterfaceperson{}publicclassemployeeextendsperson{}b.publicinterfaceshape{}publicinterfacerectandleextendsshape{}c.publicinterfacecolorable{}publicclassshapeimplementscolorable{}d.publicclassspecies{}publicclassanimal{privatespeciesspecies;}e.interfacecomponent{}classcontainerimplementscomponent{privatecomponent[]children;}解答:d,e点评:在java中代码重用有两种可能的方式,即组合(hasa 关系)和继承(isa 关系)。
hasa 关系是通过定义类的属性的方式实现的;而isa 关系是通过类继承实现的。
本例中选项a、b、c体现了isa 关系;选项d、e体现了hasa 关系。
例题6:whichtwostatementsaretruefortheclassjava.util.treeset?(ch oosetwo)a.theelementsinthecollectionareordered.b.thecollectionisguaranteedtobeimmutable.c.theelementsinthecollectionareguaranteedtobeunique.d.theelementsinthecollectionareaccessedusingauniquekey.e.theelementsinthecollectionareguaranteedtobesynchroni zed解答:a,c点评:treeset类实现了set接口。
SCJP试题分析2
B. The application compiles and print “DONE WAITING”
C. The d print “FINALLY”
D. The application compiles and print “ALL DONE”
例题3:
Consider the following class:
1. class Test(int i) {
2. void test(int i) {
3. System.out.println(“I am an int.”);
4. }
5. void test(String s) {
C. The code will compile but will throw an exception at line 12.
D. The code will compile and produce the following output: I am an int.
E. The code will compile and produce the following output: I am a String.
3. new Z();
4. }
5.
6. Z() {
7. Z alias1 = this;
8. Z alias2 = this;
9. synchronized(alias1) {
10. try {
11. alias2.wait();
12. System.out.println(“DONE WAITING”);
2. g.drawString(“Any question”, 10, 0);
Java_SCJP_Marcus_Green_SCJP_Exam_2
Java Programmer Certification Mock Exam No 2Last updated 29 Dec 200260 QuestionsCopyright ©Marcus Green 2002Buy Java Certification books containg more mock exams at /bookreviews/jcertbooks.htmThis is my mock Exam No 2 based on the Objectives for the Sun Java Programmers Exam. It was created by Marcus Green(mail@) and may be freely distributed so long as it is unmodified. Please email me if you have any corrections or comments, but please read this document first/homepage/getanswers.htm.If you obtained this exam from some other source please email me to let me know and check out the latest version at .Want to ask a question about this exam?You can post a message on the discussion forum at /discus. You could also send me your question but I get heaps of email and my answer is likely to be slow and brief.It really does come with answersYes, this is a long document (around 35 pages if you were to print it out), if you cannot see the answers then you have not got the entire document, try reloading it untill you can see the answer to Question 60 and the words "End of document". If you cannot load it just keep trying.The answers contain references to approximately which objective the question relates to. If you have a query about any of these questions, please, please include the full answerwith the question. You can jump back from an answer to the question by pressing the back button on your web browser.How does this compare with the real thing?As of 5 Oct 2000 the question format has changed very slightly. You will now get more questions that include snippets of code (though the ratio may be similar to this mock exam). Each question will also tell you how many of the options you need to pick. You can read more about these revisions at/faq/ExamUpdate.htm. You should assume that the real thing will be harder though many people have told me that they get similar marks in the real thing to my exams... You can find a comparison between my exams and some other exams at/Enthuse/jsp/ViewAllResults.jspWhere can you find other Mock Exams?Check out my FAQ at /faq/jcertfaq.htm for links to other mock exams You can check out my first mock exam that contains 60 question at /mockexams/exam1.htmQuestionsQuestion 1)What will happen when you attempt to compile and run this code?abstract class Base{abstract public void myfunc();public void another(){System.out.println("Another method");}}public class Abs extends Base{public static void main(String argv[]){Abs a = new Abs();a.amethod();}public void myfunc(){System.out.println("My Func");}public void amethod(){myfunc();}}1) The code will compile and run, printing out the words "My Func"2) The compiler will complain that the Base class has non abstract methods3) The code will compile but complain at run time that the Base class has non abstract methods4) The compiler will complain that the method myfunc in the base class has no body, nobody at all to looove itAnswer to Question 1Question 2)What will happen when you attempt to compile and run this code?public class MyMain{public static void main(String argv){System.out.println("Hello cruel world");}}1) The compiler will complain that main is a reserved word and cannot be used for a class2) The code will compile and when run will print out "Hello cruel world"3) The code will compile but will complain at run time that no constructor is defined4) The code will compile but will complain at run time that main is not correctly definedAnswer to Question 2Question 3)Which of the following are Java modifiers?1) public2) private3) friendly4) transient5) vagrantAnswer to Question 3Question 4)What will happen when you attempt to compile and run this code?class Base{abstract public void myfunc();public void another(){System.out.println("Another method");}}public class Abs extends Base{public static void main(String argv[]){ Abs a = new Abs();a.amethod();}public void myfunc(){System.out.println("My func"); }public void amethod(){myfunc();}}1) The code will compile and run, printing out the words "My Func"2) The compiler will complain that the Base class is not declared as abstract.3) The code will compile but complain at run time that the Base class has non abstract methods4) The compiler will complain that the method myfunc in the base class has no body, nobody at all to looove itAnswer to Question 4Question 5)Why might you define a method as native?1) To get to access hardware that Java does not know about2) To define a new data type such as an unsigned integer3) To write optimised code for performance in a language such as C/C++4) To overcome the limitation of the private scope of a methodAnswer to Question 5Question 6)What will happen when you attempt to compile and run this code?class Base{public final void amethod(){System.out.println("amethod");}}public class Fin extends Base{public static void main(String argv[]){Base b = new Base();b.amethod();}}1) Compile time error indicating that a class with any final methods must be declared final itself2) Compile time error indicating that you cannot inherit from a class with final methods3) Run time error indicating that Base is not defined as final4) Success in compilation and output of "amethod" at run time.Answer to Question 6Question 7)What will happen when you attempt to compile and run this code?public class Mod{public static void main(String argv[]){}public static native void amethod();}1) Error at compilation: native method cannot be static2) Error at compilation native method must return value3) Compilation but error at run time unless you have made code containing native amethod available4) Compilation and execution without errorAnswer to Question 7Question 8)What will happen when you attempt to compile and run this code?private class Base{}public class Vis{transient int iVal;public static void main(String elephant[]){}}1)Compile time error: Base cannot be private2)Compile time error indicating that an integer cannot be transient3)Compile time error transient not a data type4)Compile time error malformed main methodAnswer to Question 8Question 9)What happens when you attempt to compile and run these two files in the same directory?//File P1.javapackage MyPackage;class P1{void afancymethod(){System.out.println("What a fancy method");}}//File P2.javapublic class P2 extends P1{public static void main(String argv[]){P2 p2 = new P2();p2.afancymethod();}}1) Both compile and P2 outputs "What a fancy method" when run2) Neither will compile3) Both compile but P2 has an error at run time4) P1 compiles cleanly but P2 has an error at compile timeAnswer to Question 9Question 10)You want to find out the value of the last element of an array. You write the following code. What will happen when you compile and run it.?public class MyAr{public static void main(String argv[]){int[] i = new int[5];System.out.println(i[5]);}}1) An error at compile time2) An error at run time3) The value 0 will be output4) The string "null" will be outputAnswer to Question 10Question 11)You want to loop through an array and stop when you come to the last element. Being a good java programmer and forgetting everything you ever knew about C/C++ you know that arrays contain information about their size. Which of the following can you use?1)myarray.length();2)myarray.length;3)myarray.size4)myarray.size();Answer to Question 11Question 12)What best describes the appearance of an application with the following code?import java.awt.*;public class FlowAp extends Frame{public static void main(String argv[]){FlowAp fa=new FlowAp();fa.setSize(400,300);fa.setVisible(true);}FlowAp(){add(new Button("One"));add(new Button("Two"));add(new Button("Three"));add(new Button("Four"));}//End of constructor}//End of Application1) A Frame with buttons marked One to Four placed on each edge.2) A Frame with buutons marked One to four running from the top to bottom3) A Frame with one large button marked Four in the Centre4) An Error at run time indicating you have not set a LayoutManagerAnswer to Question 12Question 13)How do you indicate where a component will be positioned using Flowlayout?1) North, South,East,West2) Assign a row/column grid reference3) Pass a X/Y percentage parameter to the add method4) Do nothing, the FlowLayout will position the componentAnswer to Question 13)Question 14)How do you change the current layout manager for a container1) Use the setLayout method2) Once created you cannot change the current layout manager of a component3) Use the setLayoutManager method4) Use the updateLayout methodAnswer to Question 14)Question 15)Which of the following are fields of the GridBagConstraints class?1) ipadx2) fill3) insets4) widthAnswer to Question 15)Question 16)What most closely matches the appearance when this code runs?import java.awt.*;public class CompLay extends Frame{public static void main(String argv[]){CompLay cl = new CompLay();}CompLay(){Panel p = new Panel();p.setBackground(Color.pink);p.add(new Button("One"));p.add(new Button("Two"));p.add(new Button("Three"));add("South",p);setLayout(new FlowLayout());setSize(300,300);setVisible(true);}}1) The buttons will run from left to right along the bottom of the Frame2) The buttons will run from left to right along the top of the frame3) The buttons will not be displayed4) Only button three will show occupying all of the frameAnswer to Question 16)Question 17)Which statements are correct about the anchor field?1) It is a field of the GridBagLayout manager for controlling component placement2) It is a field of the GridBagConstraints class for controlling component placement3) A valid setting for the anchor field is GridBagConstraints.NORTH4) The anchor field controls the height of components added to a container Answer to Question 17)Question 18)What will happen when you attempt to compile and run the following code?public class Bground extends Thread{public static void main(String argv[]){Bground b = new Bground();b.run();}public void start(){for (int i = 0; i <10; i++){System.out.println("Value of i = " + i);}}}1) A compile time error indicating that no run method is defined for the Thread class2) A run time error indicating that no run method is defined for the Thread class3) Clean compile and at run time the values 0 to 9 are printed out4) Clean compile but no output at runtimeAnswer to Question 18)Question 19)Is the following statement true or false?When using the GridBagLayout manager, each new component requires a new instance of the GridBagConstraints class.1) true2) falseAnswer to Question 19)Question 20)Which most closely matches a description of a Java Map?1) A vector of arrays for a 2D geographic representation2) A class for containing unique array elements3) A class for containing unique vector elements4) An interface that ensures that implementing classes cannot contain duplicate keysAnswer to Question 20)Question 21)How does the set collection deal with duplicate elements?1) An exception is thrown if you attempt to add an element with a duplicate value2) The add method returns false if you attempt to add an element with a duplicate value3) A set may contain elements that return duplicate values from a call to the equals method4) Duplicate values will cause an error at compile timeAnswer to Question 21)Question 22)What can cause a thread to stop executing?1) The program exits via a call to System.exit(0);2) Another thread is given a higher priority3) A call to the thread's stop method.4) A call to the halt method of the Thread class?Answer to Question 22)Question 23)For a class defined inside a method, what rule governs access to the variables of the enclosing method?1) The class can access any variable2) The class can only access static variables3) The class can only access transient variables4) The class can only access final variablesAnswer to Question 23)Question 24)Under what circumstances might you use the yield method of the Thread class1) To call from the currently running thread to allow another thread of the same or higher priority to run2) To call on a waiting thread to allow it to run3) To allow a thread of higher priority to run4) To call from the currently running thread with a parameter designating which thread should be allowed to runAnswer to Question 24)Question 25)What will happen when you attempt to compile and run the following codepublic class Hope{public static void main(String argv[]){Hope h = new Hope();}protected Hope(){for(int i =0; i <10; i ++){System.out.println(i);}}}1) Compilation error: Constructors cannot be declared protected2) Run time error: Constructors cannot be declared protected3) Compilation and running with output 0 to 104) Compilation and running with output 0 to 9Answer to Question 25)Question 26)What will happen when you attempt to compile and run the following codepublic class MySwitch{public static void main(String argv[]){MySwitch ms= new MySwitch();ms.amethod();}public void amethod(){int k=10;switch(k){default: //Put the default at the bottom, not here System.out.println("This is the default output");break;case 10:System.out.println("ten");case 20:System.out.println("twenty");break;}}}1) None of these options2) Compile time error target of switch must be an integral type3) Compile and run with output "This is the default output"4) Compile and run with output of the single line "ten"Answer to Question 26)Question 27)Which of the following is the correct syntax for suggesting that the JVM performs garbage collection1) System.free();2) System.setGarbageCollection();3) System.out.gc();4) System.gc();Answer to Question 27)Question 28)What will happen when you attempt to compile and run the following codepublic class As{int i = 10;int j;char z= 1;boolean b;public static void main(String argv[]){As a = new As();a.amethod();}public void amethod(){System.out.println(j);System.out.println(b);}}1) Compilation succeeds and at run time an output of 0 and false2) Compilation succeeds and at run time an output of 0 and true3) Compile time error b is not initialised4) Compile time error z must be assigned a char valueAnswer to Question 28)Question 29)What will happen when you attempt to compile and run the following code with the command line "hello there"public class Arg{String[] MyArg;public static void main(String argv[]){MyArg=argv;}public void amethod(){System.out.println(argv[1]);}}1) Compile time error2) Compilation and output of "hello"3) Compilation and output of "there"4) None of the aboveAnswer to Question 29)Question 30)What will happen when you attempt to compile and run the following codepublic class StrEq{public static void main(String argv[]){StrEq s = new StrEq();}private StrEq(){String s = "Marcus";String s2 = new String("Marcus");if(s == s2){System.out.println("we have a match");}else{System.out.println("Not equal"); }}}1) Compile time error caused by private constructor2) Output of "we have a match"3) Output of "Not equal"4) Compile time error by attempting to compare strings using ==Answer to Question 30)Question 31)What will happen when you attempt to compile and run the following codeimport java.io.*;class Base{public void amethod()throws FileNotFoundException{} }public class ExcepDemo extends Base{public static void main(String argv[]){ExcepDemo e = new ExcepDemo();}public void amethod(){}protected ExcepDemo(){try{DataInputStream din = newDataInputStream(System.in);System.out.println("Pausing");din.readByte();System.out.println("Continuing");this.amethod();}catch(IOException ioe) {}}}1) Compile time error caused by protected constructor2) Compile time error caused by amethod not declaring Exception3) Runtime error caused by amethod not declaring Exception4) Compile and run with output of "Pausing" and "Continuing" after a key is hit Answer to Question 31)Question 32)What will happen when you attempt to compile and run this programpublic class Outer{public String name = "Outer";public static void main(String argv[]){Inner i = new Inner();i.showName();}//End of mainprivate class Inner{String name =new String("Inner");void showName(){System.out.println(name);}}//End of Inner class}1) Compile and run with output of "Outer"2) Compile and run with output of "Inner"3) Compile time error because Inner is declared as private4) Compile time error because of the line creating the instance of Inner Answer to Question to 32Question 33)What will happen when you attempt to compile and run this code//Demonstration of event handlingimport java.awt.*;import java.awt.event.*;public class MyWc extends Frame implements WindowListener{ public static void main(String argv[]){MyWc mwc = new MyWc();}public void windowClosing(WindowEvent we){System.exit(0);}//End of windowClosingpublic void MyWc(){setSize(300,300);setVisible(true);}}//End of class1) Error at compile time2) Visible Frame created that that can be closed3) Compilation but no output at run time4) Error at compile time because of comment before import statements Answer to Question 33)Question 34)Which option most fully describes will happen when you attempt to compile and run the following codepublic class MyAr{public static void main(String argv[]) {MyAr m = new MyAr();m.amethod();}public void amethod(){static int i;System.out.println(i);}}1) Compilation and output of the value 02) Compile time error because i has not been initialized3) Compilation and output of null4) Compile time errorAnswer to Question 34)Question 35)Which of the following will compile correctly1) short myshort = 99S;2) String name = 'Excellent tutorial Mr Green';3) char c = 17c;4)int z = 015;Answer to Question 35)Question 36)Which of the following are Java key words1)double2)Switch3)then4)instanceofAnswer to Question 36)Question 37)What will be output by the following line?System.out.println(Math.floor(-2.1));1) -22) 2.03) -34) -3.0Answer to Question 37)Question 38)Given the following main method in a class called Cycle and a command line of java Cycle one twowhat will be output?public static void main(String bicycle[]){System.out.println(bicycle[0]);}1) None of these options2) cycle3) one4) twoAnswer to Question 38)Question 39)Which of the following statements are true?1) At the root of the collection hierarchy is a class called Collection2) The collection interface contains a method called enumerator3) The interator method returns an instance of the Vector class4) The Set interface is designed for unique elementsAnswer to Question 39)Question 40)Which of the following statements are correct?1) If multiple listeners are added to a component only events for the last listener added will be processed2) If multiple listeners are added to a component the events will be processed for all but with no guarantee in the order3) Adding multiple listeners to a comnponent will cause a compile time error4) You may remove as well add listeners to a component.Answer to Question 40)Question 41)Given the following codeclass Base{}public class MyCast extends Base{static boolean b1=false;static int i = -1;static double d = 10.1;public static void main(String argv[]){MyCast m = new MyCast();Base b = new Base();//Here}}Which of the following, if inserted at the comment //Here will allow the code to compile and run without error1) b=m;2) m=b;3) d =i;4) b1 =i;Answer to Question 41)Question 42)Which of the following statements about threading are true1) You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements runnable2) You can obtain a mutually exclusive lock on any object3) A thread can obtain a mutually exclusive lock on an object by calling a method synchronized on that object.4) Thread scheduling algorithms are platform dependentAnswer to Question 42)Question 43)Your chief Software designer has shown you a sketch of the new Computer parts system she is about to create. At the top of the hierarchy is a Class called Computer and under this are two child classes. One is called LinuxPC and one is called WindowsPC.The main difference between the two is that one runs the Linux operating System and the other runs the Windows System (of course another difference is that one needs constant re-booting and the other runs reliably). Under the WindowsPC are two Sub classes one called Server and one Called Workstation. How might you appraise your designers work?1) Give the goahead for further design using the current scheme2) Ask for a re-design of the hierarchy with changing the Operating System to a field rather than Class type3) Ask for the option of WindowsPC to be removed as it will soon be obsolete4) Change the hierarchy to remove the need for the superfluous Computer Class.Answer to Question 43)Question 44)Which of the following statements are true1) An inner class may be defined as static2) There are NO circumstances where an inner class may be defined as private3) A programmer may only provide one constructor for an anonymous class4) An inner class may extend another classAnswer to Question 44)Question 45)What will happen when you attempt to compile and run the following codeint Output=10;boolean b1 = false;if((b1==true) && ((Output+=10)==20)){System.out.println("We are equal "+Output);}elseSystem.out.println("Not equal! "+Output);}1) Compile error, attempting to peform binary comparison on logical data type2) Compilation and output of "We are equal 10"3) Compilation and output of "Not equal! 20"4) Compilation and output of "Not equal! 10"Answer to Question 45)Question 46)Given the following variables which of the following lines will compile without error?String s = "Hello";long l = 99;double d = 1.11;int i = 1;int j = 0;1) j= i <<s;2) j= i<<j;3) j=i<<d;4)j=i<<l;Answer to Question 46)Question 47)What will be output by the following line of code?System.out.println(010|4);2) 03) 64) 12Answer to Question 47)Question 48)Given the following variableschar c = 'c';int i = 10;double d = 10;long l = 1;String s = "Hello";Which of the following will compile without error?1)c=c+i;2)s+=i;3)i+=s;4)c+=s;Answer to Question 48)Question 49)Which of the following will compile without error?1) File f = new File("/","autoexec.bat");2) DataInputStream d = new DataInputStream(System.in);3) OutputStreamWriter o = new OutputStreamWriter(System.out);4) RandomAccessFile r = new RandomAccessFile("OutFile"); Answer to Question 49)Question 50)Given the folowing classes which of the following will compile without error?interface IFace{}class CFace implements IFace{}class Base{}public class ObRef extends Base{public static void main(String argv[]){ObRef ob = new ObRef();Base b = new Base();Object o1 = new Object();IFace o2 = new CFace();}}1)o1=o2;2)b=ob;3)ob=b;4)o1=b;Answer to Question 50)Question 51)Given the following code what will be the output?class ValHold{public int i = 10;}public class ObParm{public static void main(String argv[]){ObParm o = new ObParm();o.amethod();}public void amethod(){int i = 99;ValHold v = new ValHold();v.i=30;another(v,i);System.out.print( v.i );}//End of amethodpublic void another(ValHold v, int i){i=0;v.i = 20;ValHold vh = new ValHold();v = vh;System.out.print(v.i);System.out.print(i);}//End of another}1) 100302) 200303) 2099304) 10020Answer to Question 51)Question 52)Given the following class definition, which of the following methods could be legally placed after the comment//Herepublic class Rid{public void amethod(int i, String s){}//Here}1)public void amethod(String s, int i){}2)public int amethod(int i, String s){}3)public void amethod(int i, String mystring){}4) public void Amethod(int i, String s) {}Answer to Question 52)Question 53)Given the following class definition which of the following can be legally placed after the comment line//Here ?class Base{public Base(int i){}}public class MyOver extends Base{public static void main(String arg[]){MyOver m = new MyOver(10);}MyOver(int i){super(i);}MyOver(String s, int i){this(i);//Here}}1)MyOver m = new MyOver();2)super();3)this("Hello",10);4)Base b = new Base(10);Answer to Question 53)Question 54)Given the following class definition, which of the following statements would be legal after the comment //Hereclass InOut{String s= new String("Between");public void amethod(final int iArgs){int iam;class Bicycle{public void sayHello(){//Here}}//End of bicycle class}//End of amethodpublic void another(){int iOther;}}1) System.out.println(s);2) System.out.println(iOther);3) System.out.println(iam);4) System.out.println(iArgs);Answer to Question 54)Question 55)Which of the following are methods of the Thread class?1) yield()2) sleep(long msec)3) go()4) stop()Answer to Question 55)。
java英语笔试试题及答案
java英语笔试试题及答案Java英语笔试试题及答案1. What is the difference between a class and an object in Java?A class is a blueprint or template that defines the properties and methods of an object. An object is an instance of a class, created at runtime.2. What is the purpose of the 'public static voidmain(String[] args)' method in Java?The 'public static void main(String[] args)' method is the entry point of a Java application. It is the first methodthat gets executed when the program starts.3. What is the difference between a method and a function in Java?In Java, a method is a block of code that is used to perform a specific task. A function is a term that is often used interchangeably with method, but technically, a function can return a value whereas a method does not necessarily do so.4. What is the 'this' keyword used for in Java?The 'this' keyword in Java is a reference to the current object. It can be used to access instance variables and methods of the current object.5. What is an interface in Java?An interface in Java is a completely abstract class that can contain only abstract methods and constants. It is used to achieve abstraction and to define a contract for classes to implement.6. What is the difference between a checked exception and an unchecked exception in Java?A checked exception is a type of exception that a method must either handle with a try-catch block or declare it with the 'throws' keyword. An unchecked exception is not required to be handled or declared, and includes RuntimeException and its subclasses.7. What is the 'final' keyword used for in Java?The 'final' keyword in Java can be used in three different contexts: to declare a class as final (cannot be subclassed), to declare a method as final (cannot be overridden), or to declare a variable as final (cannot be reassigned).8. What is a constructor in Java?A constructor in Java is a special method that is used to initialize objects. It has the same name as the class and is called when an object is created.9. What is the purpose of the 'super' keyword in Java?The 'super' keyword in Java is used to refer to the parent class's methods and variables. It is often used in constructors to call a superclass's constructor.10. What is the difference b etween '==’ and 'equals()' inJava?The '==' operator is used to compare primitive data types by value and object references by reference, whereas the'equals()' method is used to compare objects by content, and it can be overridden to provide custom comparison logic.Answers:1. A class is a blueprint, an object is an instance of a class.2. It is the entry point of a Java application.3. A method is a block of code in Java, a function is a more general term and can return a value.4. It refers to the current object.5. An interface is an abstract class with only abstract methods and constants.6. Checked exceptions must be handled or declared, unchecked do not.7. It is used to declare classes, methods, or variables as final.8. It initializes objects.9. It refers to the parent class's methods and variables.10. '==' compares by value or reference, 'equals()' compares by content.。
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关键字:可以用来修饰方法或代码块,确保同一时间只有一个线程可以访问被修饰的代码,从而避免竞态条件和数据不一致的问题。
Java2022年二级试卷
Java2022年二级试卷Java2022年二级试卷一、多选题(共30题,共60分)1.下面哪些可以使用static关键字修饰?(多选)A.成员变量B.局部变量C.成员方法D.成员内部类2.使用this调用类的构造方法,下面的说法正确的是?(多选)A.使用this调用构造方法的格式为this([参数1,参数2…])B.只能在构造方法中使用this调用其它的构造方法C.使用this调用其它构造方法的语句必须放在第一行D.不能在一个类的两个构造方法中使用this互相调用3.下面对于构造方法的描述,正确有哪些?(多选)A.方法名必须和类名相同B.方法名的前面没有返回值类型的声明C.在方法中不能使用return语句返回一个值D.当定义了带参数的构造方法,系统默认的不带参数的构造方法依然存在4.在以下什么情况下,构造方法会被调用?A.类定义时B.创建对象时C.调用对象方法时D.使用对象的变量时5.下面哪一个是正确的类的声明?A.publicvoidHH{…}B.publicclassMove(){…}C.publicclassvoidnumber{}D.publicclassCar{…}6.类的定义必须包含在以下哪种符号之间?A.方括号[]B.花括号{}C.双引号“”D.圆括号()7.TCP协议的“三次握手”中,第一次握手指的是什么?()A.客户端再次向服务器端发送确认信息,确认连接B.服务器端向客户端回送一个响应,通知客户端收到了连接请求C.客户端向服务器端发出连接请求,等待服务器确认D.以上答案全部错误8.在程序运行时,DatagramSocket的那个方法会发生阻塞()A.send()B.receive()C.close()D.connect()9.以下哪个方法是DatagramSocket类用于发送数据的方法?()A.receive()B.accept()C.set()D.send()10.进行UDP通信时,在接收端若要获得发送端的IP地址,可以使用DatagramPacket的哪个方法?A.getAddress()B.getPort()C.getName()D.getData()11.以下哪个类用于实现TCP通信的客户端程序?()A.ServerSocketB.SocketC.ClientD.Server12.以下说法哪些是正确的?(多选)()A.TCP连接中必须要明确客户端与服务器端B.TCP协议是面向连接的通信协议,它提供了两台计算机之间可靠无差错的数据传输C.UDP协议是面向无连接的协议,可以保证数据的完整性D.UDP协议消耗资源小,通信效率高,通常被用于音频、视频和普通数据的传输13.以下哪个是serverSocket类用于接收来自客户端请求的方法?()A.accept()B.getOutputStream()"C.receive()D.get()14.使用UDP协议通信时,需要使用哪个类把要发送的数据打包?A.SocketCmtB.DatagramSocketC.DatagramPacketD.ServerSocket15.使用下面哪个组件可以接收用户的输入信息?A.JButtonB.JLabelC.JTextFieldD.以上都可以16.下面四对AWT和Swing对应组件中,错误的是?A.Button和JButtonB.Dialog和JDialogC.MenuBar和JMenuBarboBox和JComboBox17.下面对与Swing的描述,正确的有哪些?(多选)A.Swing是在AWT基础上构建的一套新的图形界面系统B.Swing提供了AWT所能够提供的所有功能C.Swing组件是用Java代码来实现的D.Swing组件都是重量级组件18.下面哪些是FlowLayout类中表示对齐方式的常量?(多选)A.FlowLayout.LEFTB.FlowLayout.CENTERC.FlowLayout.VERTICALD.FlowLayout.RIGHT19.AWT中,常用的布局管理器包括哪些?(多选)A.FlowLayout布局管理器B.BorderLayout布局管理器C.CardLayout布局管理器D.GridLayout布局管理器20.ActionEvent的对象会被传递给以下哪个事件处理器方法?A.addChangeListener()B.addActionListener()C.stateChanged()D.actionPerformed()21.当鼠标按键被释放时,会调用以下哪个事件处理器方法?A.mouseReleased()B.mouseUp()C.mouseOff()D.mouseLetGo()22.每一个GUI程序中必须包含一个什么组件?A.按钮B.标签C.菜单D.容器23.下面四个选项中,哪些是事件处理机制中的角色?(多选)A.事件B.事件源C.事件接口D.事件监听器24.下面四个组件中哪一个不是Component的子类?A.ButtonB.DialogbelD.MenuBar25.以下对File类的publicbooleaisFile()方法的描述,哪个是正确的?A.判断该File对象所对应的是否是文件。
(整理)SCJP认证试题及答案.
转载对题目和答案谨做参考Q1A method is ...1) an implementation of an abstraction.2) an attribute defining the property of a particular abstraction.3) a category of objects.4) an operation defining the behavior for a particular abstraction.5) a blueprint for making operations.Q2An object is ...1) what classes are instantiated from.2) an instance of a class.3) a blueprint for creating concrete realization of abstractions.4) a reference to an attribute.5) a variable.Q3Which line contains a constructor in this class definition?public class Counter { // (1)int current, step;public Counter(int startValue, int stepValue) { // (2)set(startValue);setStepValue(stepValue);}public int get() { return current; } // (3)public void set(int value) { current = value; } // (4)public void setStepValue(int stepValue) { step = stepValue; } // (5) }1) Code marked with (1) is a constructor2) Code marked with (2) is a constructor3) Code marked with (3) is a constructor4) Code marked with (4) is a constructor5) Code marked with (5) is a ConstructorQ4Given that Thing is a class, how many objects and reference variables are created by the following code?Thing item, stuff;item = new Thing();Thing entity = new Thing();1) One object is created2) Two objects are created3) Three objects are created4) One reference variable is created5) Two reference variables are created6) Three reference variables are created.Q5An instance member…1) is also called a static member2) is always a variable3) is never a method4) belongs to a single instance, not to the class as a whole5) always represents an operationQ6How do objects pass messages in Java?1) They pass messages by modifying each other's member variables2) They pass messages by modifying the static member variables of each other's classes3) They pass messages by calling each other's instance member methods4) They pass messages by calling static member methods of each other's classes.Q7Given the following code, which statements are true?class A {int value1;}class B extends A {int value2;}1) Class A extends class B.2) Class B is the superclass of class A.3) Class A inherits from class B.4) Class B is a subclass of class A.5) Objects of class A have a member variable named value2.Q8If this source code is contained in a file called SmallProg.java, what command should be used to compile it using the JDK?public class SmallProg {public static void main(String args[]) { System.out.println("Good luck!"); }}1) java SmallProg2) avac SmallProg3) java SmallProg.java4) javac SmallProg.java5) java SmallProg mainQ9Given the following class, which statements can be inserted at position 1 without causing the code to fail compilation?public class Q6db8 {int a;int b = 0;static int c;public void m() {int d;int e = 0;// Position 1}}1) a++;2) b++;3) c++;4) d++;5) e++;Q10Which statements are true concerning the effect of the >> and >>> operators?1) For non-negative values of the left operand, the >> and >>> operators will have the same effect.2) The result of (-1 >> 1) is 0.3) The result of (-1 >>> 1) is -1.4) The value returned by >>> will never be negative as long as the value of the right operand is equal to or greater than 1.5) When using the >> operator, the leftmost bit of the bit representation of the resulting value will always be the same bit value as the leftmost bit of the bit representation of the left operand.Q11What is wrong with the following code?class MyException extends Exception {}public class Qb4ab {public void foo() {try {bar();} finally {baz();} catch (MyException e) {}}public void bar() throws MyException {throw new MyException();}public void baz() throws RuntimeException {throw new RuntimeException();}}1) Since the method foo() does not catch the exception generated by the method baz(), it must declare the RuntimeException in its throws clause.2) A try block cannot be followed by both a catch and a finally block.3) An empty catch block is not allowed.4) A catch block cannot follow a finally block.5) A finally block must always follow one or more catch blocks.Q12What will be written to the standard output when the following program is run?public class Qd803 {public static void main(String args[]) {String word = "restructure";System.out.println(word.substring(2, 3));}}1) est2) es3) str4) st5) sQ13Given that a static method doIt() in a class Work represents work to be done, what block of code willsucceed in starting a new thread that will do the work?CODE BLOCK A:Runnable r = new Runnable() {public void run() {Work.doIt();}};Thread t = new Thread(r);t.start();CODE BLOCK B:Thread t = new Thread() {public void start() {Work.doIt();}};t.start();CODE BLOCK C:Runnable r = new Runnable() {public void run() {Work.doIt();}};r.start();CODE BLOCK D:Thread t = new Thread(new Work());t.start();CODE BLOCK E:Runnable t = new Runnable() {public void run() {Work.doIt();}};t.run();1) Code block A.2) Code block B.3) Code block C.4) Code block D.5) Code block E.Q14Write a line of code that declares a variable named layout of type LayoutManager and initializes it with a new object, which when used with a container can lay out components in a rectangular grid of equal-sized rectangles, 3 components wide and 2 components high.Q15public class Q275d {static int a;int b;public Q275d() {int c;c = a;a++;b += c;}public static void main(String args[]) {new Q275d();}}1) The code will fail to compile, since the constructor is trying to access static members.2) The code will fail to compile, since the constructor is trying to use static member variable a before it has been initialized.3) The code will fail to compile, since the constructor is trying to use member variable b before it has been initialized.4) The code will fail to compile, since the constructor is trying to use local variable c before it has been initialized.5) The code will compile and run without any problems.Q16What will be written to the standard output when the following program is run?public class Q63e3 {public static void main(String args[]) {System.out.println(9 ^ 2);}}1) 812) 73) 114) 05) falseQ17Which statements are true concerning the default layout manager for containers in the java.awt package?1) Objects instantiated from Panel do not have a default layout manager.2) Objects instantiated from Panel have FlowLayout as default layout manager.3) Objects instantiated from Applet have BorderLayout as default layout manager.4) Objects instantiated from Dialog have BorderLayout as default layout manager.5) Objects instantiated from Window have the same default layout manager as instances of Applet.Q18Which declarations will allow a class to be started as a standalone program?1) public void main(String args[])2) public void static main(String args[])3) public static main(String[] argv)4) final public static void main(String [] array)5) public static void main(String args[])Q19Under which circumstances will a thread stop?1) The method waitforId() in class MediaTracker is called.2) The run() method that the thread is executing ends.3) The call to the start() method of the Thread object returns.4) The suspend() method is called on the Thread object.5) The wait() method is called on the Thread object.Q20When creating a class that associates a set of keys with a set of values, which of these interfaces is most applicable?1) Collection2) Set3) SortedSet4) MapQ21What does the value returned by the method getID() found in class java.awt.AWTEvent uniquely identify?1) The particular event instance.2) The source of the event.3) The set of events that were triggered by the same action.4) The type of event.5) The type of component from which the event originated.Q22What will be written to the standard output when the following program is run?class Base {int i;Base() {add(1);}void add(int v) {i += v;}void print() {System.out.println(i);}}class Extension extends Base {Extension() {add(2);}void add(int v) {i += v*2;}}public class Qd073 {public static void main(String args[]) {bogo(new Extension());}static void bogo(Base b) {b.add(8);b.print();}}1) 92) 183) 204) 215) 22Q23Which lines of code are valid declarations of a native method when occurring within the declaration of the following class?public class Qf575 {// insert declaration of a native method here}1) native public void setTemperature(int kelvin);2) private native void setTemperature(int kelvin);3) protected int native getTemperature();4) public abstract native void setTemperature(int kelvin);5) native int setTemperature(int kelvin) {}Q24How does the weighty property of the GridBagConstraints objects used in grid bag layout affect the layout of the components?1) It affects which grid cell the components end up in.2) It affects how the extra vertical space is distributed.3) It affects the alignment of each component.4) It affects whether the components completely fill their allotted display area vertically.Q25Which statements can be inserted at the indicated position in the following code to make the program write 1 on the standard output when run?public class Q4a39 {int a = 1;int b = 1;int c = 1;class Inner {int a = 2;int get() {int c = 3;// insert statement herereturn c;}}Q4a39() {Inner i = new Inner();System.out.println(i.get());}public static void main(String args[]) {new Q4a39();}}1) c = b;2) c = this.a;3) c = this.b;4) c = Q4a39.this.a;5) c = c;Q26Which is the earliest line in the following code after which the object created on the line marked (0) will be a candidate for being garbage collected, assuming no compiler optimizations are done?public class Q76a9 {static String f() {String a = "hello";String b = "bye"; // (0)String c = b + "!"; // (1)String d = b;b = a; // (2)d = a; // (3)return c; // (4)}public static void main(String args[]) {String msg = f();System.out.println(msg); // (5)}}1) The line marked (1).2) The line marked (2).3) The line marked (3).4) The line marked (4).5) The line marked (5).Q27Which methods from the String and StringBuffer classes modify the object on which they are called?1) The charAt() method of the String class.2) The toUpperCase() method of the String class.3) The replace() method of the String class.4) The reverse() method of the StringBuffer class.5) The length() method of the StringBuffer class.Q28Which statements, when inserted at the indicated position in the following code, will cause a runtime exception when attempting to run the program?class A {}class B extends A {}class C extends A {}public class Q3ae4 {public static void main(String args[]) {A x = new A();B y = new B();C z = new C();// insert statement here}}1) x = y;2) z = x;3) y = (B) x;4) z = (C) y;5) y = (A) y;Q29Which of these are keywords in Java?1) default2) NULL3) String4) throws5) longQ30It is desirable that a certain method within a certain class can only be accessed by classes that are defined within the same package as the class of the method. How can such restrictions be enforced?1) Mark the method with the keyword public.2) Mark the method with the keyword protected.3) Mark the method with the keyword private.4) Mark the method with the keyword package.5) Do not mark the method with any accessibility modifiers.Q31Which code fragments will succeed in initializing a two-dimensional array named tab with a size that will cause the expression tab[3][2] to access a valid element?CODE FRAGMENT A:int[][] tab = {{ 0, 0, 0 },{ 0, 0, 0 }};CODE FRAGMENT B:int tab[][] = new int[4][];for (int i=0; iCODE FRAGMENT C:int tab[][] = {0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0};CODE FRAGMENT D:int tab[3][2];CODE FRAGMENT E:int[] tab[] = { {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0} };1) Code fragment A.2) Code fragment B.3) Code fragment C.4) Code fragment D.5) Code fragment E.Q32What will be the result of attempting to run the following program?public class Qaa75 {public static void main(String args[]) {String[][][] arr = {{ {}, null },{ { "1", "2" }, { "1", null, "3" } },{},{ { "1", null } }};System.out.println(arr.length + arr[1][2].length);}}1) The program will terminate with an ArrayIndexOutOfBoundsException.2) The program will terminate with a NullPointerException.3) 4 will be written to standard output.4) 6 will be written to standard output.5) 7 will be written to standard output.Q33Which expressions will evaluate to true if preceded by the following code?String a = "hello";String b = new String(a);String c = a;char[] d = { 'h', 'e', 'l', 'l', 'o' };1) (a == "Hello")2) (a == b)3) (a == c)4) a.equals(b)5) a.equals(d)Q34Which statements concerning the following code are true?class A {public A() {}public A(int i) { this(); }}class B extends A {public boolean B(String msg) { return false; }}class C extends B {private C() { super(); }public C(String msg) { this(); }public C(int i) {}}1) The code will fail to compile.2) The constructor in A that takes an int as an argument will never be called as a result of constructing an object of class B or C.3) Class C has three constructors.4) Objects of class B cannot be constructed.5) At most one of the constructors of each class is called as a result of constructing an object of class C.Q35Given two collection objects referenced by col1 and col2, which of these statements are true?1) The operation col1.retainAll(col2) will not modify the col1 object.2) The operation col1.removeAll(col2) will not modify the col2 object.3) The operation col1.addAll(col2) will return a new collection object,containing elements from both col1 and col2.4) The operation col1.containsAll(Col2) will not modify the col1 object.Q36Which statements concerning the relationships between the following classes are true?class Foo {int num;Baz comp = new Baz();}class Bar {boolean flag;}class Baz extends Foo {Bar thing = new Bar();double limit;}1) A Bar is a Baz.2) A Foo has a Bar.3) A Baz is a Foo.4) A Foo is a Baz.5) A Baz has a Bar.Q37Which statements concerning the value of a member variable are true, when no explicit assignments have been made?1) The value of an int is undetermined.2) The value of all numeric types is zero.3) The compiler may issue an error if the variable is used before it is initialized.4) The value of a String variable is "" (empty string).5) The value of all object variables is null.Q38Which statements describe guaranteed behavior of the garbage collection and finalization mechanisms?1) Objects are deleted when they can no longer be accessed through any reference.2) The finalize() method will eventually be called on every object.3) The finalize() method will never be called more than once on an object.4) An object will not be garbage collected as long as it is possible for an active part of the program to access it through a reference.5) The garbage collector will use a mark and sweep algorithm.Q39Which code fragments will succeed in printing the last argument given on the command line to the standard output, and exit gracefully with no output if no arguments are given?CODE FRAGMENT A:public static void main(String args[]) {if (args.length != 0)System.out.println(args[args.length-1]);}CODE FRAGMENT B:public static void main(String args[]) {try { System.out.println(args[args.length]); }catch (ArrayIndexOutOfBoundsException e) {}}CODE FRAGMENT C:public static void main(String args[]) {int ix = args.length;String last = args[ix];if (ix != 0) System.out.println(last);}CODE FRAGMENT D:public static void main(String args[]) {int ix = args.length-1;if (ix > 0) System.out.println(args[ix]);}CODE FRAGMENT E:public static void main(String args[]) {try { System.out.println(args[args.length-1]); }catch (NullPointerException e) {}}1) Code fragment A.2) Code fragment B.3) Code fragment C.4) Code fragment D.5) Code fragment E.Q40Which of these statements concerning the collection interfaces are true?1) Set extends Collection.2) All methods defined in Set are also defined in Collection.3) List extends Collection.4) All methods defined in List are also defined in Collection.5) Map extends Collection.Q41What is the name of the method that threads can use to pause their execution until signalled to continue by another thread?Fill in the name of the method (do not include a parameter list).Q42Given the following class definitions, which expression identifies whether the object referred to by obj was created by instantiating class B rather than classes A, C and D?class A {}class B extends A {}class C extends B {}class D extends A {}1) obj instanceof B2) obj instanceof A && ! (obj instanceof C)3) obj instanceof B && ! (obj instanceof C)4) obj instanceof C || obj instanceof D5) (obj instanceof A) && ! (obj instanceof C) && ! (obj instanceof D)Q43What will be written to the standard output when the following program is run?public class Q8499 {public static void main(String args[]) {double d = -2.9;int i = (int) d;i *= (int) Math.ceil(d);i *= (int) Math.abs(d);System.out.println(i);}}1) 122) 183) 84) 125) 27Q44What will be written to the standard output when the following program is run?public class Qcb90 {int a;int b;public void f() {a = 0;b = 0;int[] c = { 0 };g(b, c);System.out.println(a + " " + b + " " + c[0] + " ");}public void g(int b, int[] c) {a = 1;b = 1;c[0] = 1;}public static void main(String args[]) {Qcb90 obj = new Qcb90();obj.f();}}1) 0 0 02) 0 0 13) 0 1 04) 1 0 05) 1 0 1Q45Which statements concerning the effect of the statement gfx.drawRect(5, 5, 10, 10) are true, given that gfx is a reference to a valid Graphics object?1) The rectangle drawn will have a total width of 5 pixels.2) The rectangle drawn will have a total height of 6 pixels.3) The rectangle drawn will have a total width of 10 pixels.4) The rectangle drawn will have a total height of 11 pixels.Q46Given the following code, which code fragments, when inserted at the indicated location, will succeed in making the program display a button spanning the whole window area?import java.awt.*;public class Q1e65 {public static void main(String args[]) {Window win = new Frame();Button but = new Button("button");// insert code fragment herewin.setSize(200, 200);win.setVisible(true);}}1) win.setLayout(new BorderLayout()); win.add(but);2) win.setLayout(new GridLayout(1, 1)); win.add(but);3) win.setLayout(new BorderLayout()); win.add(but, BorderLayout.CENTER);4) win.add(but);5) win.setLayout(new FlowLayout()); win.add(but);Q47Which method implementations will write the given string to a file named "file", using UTF8 encoding?IMPLEMENTATION A:public void write(String msg) throws IOException {FileWriter fw = new FileWriter(new File("file"));fw.write(msg);fw.close();}IMPLEMENTATION B:public void write(String msg) throws IOException {OutputStreamWriter osw =new OutputStreamWriter(new FileOutputStream("file"), "UTF8");osw.write(msg);osw.close();}IMPLEMENTATION C:public void write(String msg) throws IOException { FileWriter fw = new FileWriter(new File("file"));fw.setEncoding("UTF8");fw.write(msg);fw.close();}IMPLEMENTATION D:public void write(String msg) throws IOException { FilterWriter fw = FilterWriter(new FileWriter("file"), "UTF8"); fw.write(msg);fw.close();}IMPLEMENTATION E:public void write(String msg) throws IOException { OutputStreamWriter osw = new OutputStreamWriter(new OutputStream(new File("file")), "UTF8");osw.write(msg);osw.close();}1) Implementation A.2) Implementation B.3) Implementation C.4) Implementation D.5) Implementation E.Q48Which are valid identifiers?1) _class2) $value$3) zer@4) ¥ngstr5) 2muchuqQ49What will be the result of attempting to compile and run the following program?public class Q28fd {public static void main(String args[]) {int counter = 0;l1:for (int i=10; i<0; i--) {l2:int j = 0;while (j < 10) {if (j > i) break l2;if (i == j) {counter++;continue l1;}}counter--;}System.out.println(counter);}}1) The program will fail to compile.2) The program will not terminate normally.3) The program will write 10 to the standard output.4) The program will write 0 to the standard output.5) The program will write 9 to the standard output.Q50Given the following interface definition, which definitions are valid?interface I {void setValue(int val);int getValue();}DEFINITION A:(a) class A extends I {int value;void setValue(int val) { value = val; }int getValue() { return value; }}DEFINITION B:(b) interface B extends I {void increment();}DEFINITION C:(c) abstract class C implements I {int getValue() { return 0; }abstract void increment();}DEFINITION D:(d) interface D implements I {void increment();}DEFINITION E:(e) class E implements I {int value;public void setValue(int val) { value = val; } }1) Definition A.2) Definition B.3) Definition C.4) Definition D.5) Definition E.Q51Which statements concerning the methods notify() and notifyAll() are true?1) Instances of class Thread have a method called notify().2) A call to the method notify() will wake the thread that currently owns the monitor of the object.3) The method notify() is synchronized.4) The method notifyAll() is defined in class Thread.5) When there is more than one thread waiting to obtain the monitor of an object, there is no way to be sure which thread will be notified by the notify() method.Q52Which statements concerning the correlation between the inner and outer instances of non-static inner classes are true?1) Member variables of the outer instance are always accessible to inner instances, regardless of their accessibility modifiers.2) Member variables of the outer instance can never be referred to using only the variable name within the inner instance.3) More than one inner instance can be associated with the same outer instance.4) All variables from the outer instance that should be accessible in the inner instance must be declared final.5) A class that is declared final cannot have any inner classes.Q53What will be the result of attempting to compile and run the following code?public class Q6b0c {public static void main(String args[]) {int i = 4;float f = 4.3;double d = 1.8;int c = 0;if (i == f) c++;if (((int) (f + d)) == ((int) f + (int) d)) c += 2;System.out.println(c);}}1) The code will fail to compile.2) 0 will be written to the standard output.3) 1 will be written to the standard output.4) 2 will be written to the standard output.5) 3 will be written to the standard output.Q54Which operators will always evaluate all the operands?1) ||2) +3) &&4) ? :5) %Q55Which statements concerning the switch construct are true?1) All switch statements must have a default label.2) There must be exactly one label for each code segment in a switch statement.3) The keyword continue can never occur within the body of a switch statement.4) No case label may follow a default label within a single switch statement.5) A character literal can be used as a value for a case label.Q56Which modifiers and return types would be valid in the declaration of a working main() method for a Java standalone application?1) private2) final3) static4) int5) abstractQ57What will be the appearance of an applet with the following init() method?public void init() {add(new Button("hello"));}1) Nothing appears in the applet.2) A button will cover the whole area of the applet.3) A button will appear in the top left corner of the applet.4) A button will appear, centered in the top region of the applet.5) A button will appear in the center of the applet.Q58Which statements concerning the event model of the AWT are true?1) At most one listener of each type can be registered with a component.2) Mouse motion listeners can be registered on a List instance.3) There exists a class named ContainerEvent in package java.awt.event.4) There exists a class named MouseMotionEvent in package java.awt.event.5) There exists a class named ActionAdapter in package java.awt.event.Q59Which statements are true, given the code new FileOutputStream("data", true) for creating an object of class FileOutputStream?1) FileOutputStream has no constructors matching the given arguments.2) An IOExeception will be thrown if a file named "data" already exists.3) An IOExeception will be thrown if a file named "data" does not already exist.4) If a file named "data" exists, its contents will be reset and overwritten.5) If a file named "data" exists, output will be appended to its current contents.Q60Given the following code, write a line of code that, when inserted at the indicated location, will make the overriding method in Extension invoke the overridden method in class Base on the current object.class Base {public void print() {System.out.println("base");}}class Extention extends Base {public void print() {System.out.println("extension");// insert line of implementation here}}public class Q294d {public static void main(String args[]) {Extention ext = new Extention();ext.print();}}Fill in a single line of implementation.Q61Given that file is a reference to a File object that represents a directory, which code fragments will succeed in obtaining a list of the entries in the directory?1) Vector filelist = ((Directory) file).getList();2) String[] filelist = file.directory();3) Enumeration filelist = file.contents();4) String[] filelist = file.list();5) Vector filelist = (new Directory(file)).files();Q62。
[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认证试题及答案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。
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], 朱云
因版权原因,仅展示原文概要,查看原文内容请购买。
JAVA试题英文版(答案)
一. Which two demonstrate an “is a ” relationship? (Choose Two) A.public interface Person { } //语法错了 public class Employee extendsPerson { } B. public interface Shape { } //语法错了public class Employee extends Sha pe { }C. public interface Color { } //语法错了public class Employee extends Color { }D. public class Species { }public class Animal{private Species species;}E. interface Component { }Class Container implements Component (Private Component[ ] children;二.which statement is true?A. An anonymous inner class may be declared as finalB.An anonymous inner class can be declared as privateC. An anonymous inner class can implement mutiple interfacesD. An anonymous inner class can access final variables in any enclosing scope(不能)E. Construction of an instance of a static inner class requires an instanceof the encloing outer class构造一个静态的内部类对象需要构造包含它的外部类的对象三. Given:1.package foo;2.3.public class Outer (4.public static class Inner (5.)6. )Which statement is true?A. An instance of the Inner class can be constructed with“ new Outer.Inner ()”B. An instance of the inner class cannot be constructed outside of package foo他们都是 public 的,只要在外部import 就行C. An instance of the inner class can only be constructed from within the outerclassD. From within the package bar, an instance of the inner class can be constructed with“ new inner()”四.Exhibit (展览、陈列):1 public class enclosinggone{2 public class insideone{}3}4public class inertest{5public static void main (String[] args){6enclosingone eo = new enclosingone();7//insert code here8}}Which statement at line 7 constructs an instance of the inner class?A. InsideOne ei = eo.new InsideOne();写程序试出来B. Eo.InsideOne ei = eo.new InsideOne();C InsideOne ei = EnclosingOne.new InsideOne();D.EnclosingOne InsideOne ei = eo.new InsideOne();五.1)interface Foo{2)int k=0;3)}4)public class Test implements Foo{5)public static void main(String args[]){6)int i;7)Test test =new Test();8)i=test.k;9)i=Test.k;10)i=Foo.k;11)}12) }What is the result?A. Compilation succeeds.B. An error at line 2 causes compilation to fail.C. An error at line 9 causes compilation to fail.D. An error at line 10 causes compilation to fail.E. An error at line 11 causes compilation to fail.六.//point Xpublic class Foo{public static void main(String[] args){PrintWriter out=new PrintWriter(newjava.io.OutputStreamWriter(System.out),true);out.println("Hello");}}which statement at point X on line 1 allows this code to compile and run?在 point X 这个位置要填入什么代码才能使程序运行A.import java.io.PrintWriterB. include java.io.PrintWriterC.import java.io.OutputStreamWriterD.include java.io.OutputStreamWriterE.No statement is needed本来两个都要import ,但是后者OutputStreamWriter指定了包结构java.io.OutputStreamWriter七. what is reserved words in java?保留字而非关键字A.runB.defaultC.implementD.import八. which three are valid declaraction of a float?( float 作为整数是可以的,其余几个都是double )A. float foo=-1;B. float foo=1.0;C. float foo=42e1;D. float foo=2.02f;E. float foo=3.03d;F. float foo=0x0123;九. Given:8.int index = 1;9.boolean[] test = new boolean[3]; (数组作为对象缺省初始化为false )10. boolean foo= test [index];What is the result?A. foo has the value of 0B. foo has the value of nullC. foo has the value of trueD. foo has the value of falseE. an exception is thrownF. the code will not compile十. Given:1.public class test(2.public static void main(String[]args){3.String foo = args [1];4.String foo = args [2];5.String foo = args [3];6.}7.}And the command line invocation:Java TestWhat is the result?A. baz has the value of“”B. baz has the value of nullC. baz has the value of“ red”D. baz has the value of“ blue”E. bax has the value of“ green”F. the code does not compileG. the program throws an exception(此题题目出错了,重复定义了变量foo ,如果没有重复的话,应选G,因为只传递了 0-2 三个数组元素,而题目中需要访问 args [3] ,所以会抛出数组越界异常 )十一 .int index=1;int foo[]=new int[3];int bar=foo[index]; //bar=0int baz=bar+index; //baz=1what is the result?A. baz has a value of 0B. baz has value of 1C. baz has value of 2D. an exception is thrownE. the code will not compile十二 .1)public class Foo{2) public static void main(String args[]){3) String s;4) System.out.println("s="+s);5)}6) }what is the result?A. The code compiles and“s=printed”.B. The code compiles and“ s=null” is printed.C. The code does not compile because string s is not initialized.D. The code does not compile because string s cannot be referenced.E. The code compiles, but a NullPointerException is thrown when toString is called.十三 . Which will declare a method that forces a subclass to implement it?(谁声明了一个方法,子类必须实现它)A. public double methoda();B. static void methoda (double d1) {}C. public native double methoda();D. abstract public void methoda();E. protected void methoda (double d1){}十四 .You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access modifier that will accomplish this objective?(你希望子类在任何包里都能访问父类,为完成这个目的,下列哪个是最严格的访问权限)A.PublicB.PrivateC.ProtectedD.TransientE.No access modifier is qualified十五 . Given:1.abstract class abstrctIt {2.abstract float getFloat ();3.)4.public class AbstractTest extends AbstractIt {5.private float f1= 1.0f;6.private float getFloat () {return f1;}7.}What is the result?A. Compilation is successful.B. An error on line 6 causes a runtime failure.(抛出实时异常)C. An error at line 6 causes compilation to fail.D. An error at line 2 causes compilation to fail.(子类覆盖父类方法的时候,不能比父类方法具有更严格的访问权限)十六 . Click the exhibit button:1.public class test{2.public int aMethod(){3.static int i=0;4.i++;5.return I;6.}7.public static void main (String args[]){8.test test = new test();9.test.aMethod();10. int j = test.aMethod();11. System.out.printIn(j);12. }13. }(局部变量不能声明为静态)What is the result?A. Compilation will fail.B. Compilation will succeed and the program will print“ 0”.C. Compilation will succeed and the program will print“ 1”.D. Compilation will succeed an d the program will print“ 2”.十七 .1)class Super{2)public float getNum(){return 3.0f;}3)}4)5)public class Sub extends Super{6)7)}which method, placed at line 6, will cause a compiler error?A. public float getNum(){return 4.0f;}B. public void getNum(){} 返回值类型不同不足以构成方法的重载C. public void getNum(double d){}D. public double getNum(float d){return 4.0d;}十八 . Which declaration prevents creating a subclass of an outer class?A.static class FooBar{}B.pivate class Foobar{}C.abstract class FooBar{}D.final public class FooBar{}E.final abstract class FooBar{}抽象类不能声明为final十九 . byte[] array1,array2[]byte array3[][]byte[][] array4if each has been initialized, which statement will cause a compile error?A. array2 = array1;B. array2 = array3;C. array2 = array4;D. both A and BE. both A and CF. both B and C (一维数组和二维数组的区别)二十 .class Super{public int i=0;public Super(String text){i=1;}}public class Sub extends Super{public Sub(String text){i=2;}public static void main(String args[]){Sub sub=new Sub("Hello");System.out.println(sub.i);}}what is the result?A. compile will failB. compile success and print "0"C. compile success and print "1"D. compile success and print "2"子类总要去调用父类的构造函数,有两种调用方式,自动调用(无参构造函数),主动调用带参构造函数。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
question 1)what will happen when you attempt to compile and run this code?abstract class base{abstract public void myfunc();public void another(){system.out.println("another method");}}public class abs extends base{public static void main(string argv[]){abs a = new abs();a.amethod();}public void myfunc(){system.out.println("my func");}public void amethod(){myfunc();}}1) the code will compile and run, printing out the words "my func"2) the compiler will complain that the base class has non abstract methods3) the code will compile but complain at run time that the base class has non abstract methods4) the compiler will complain that the method myfunc in the base class has no body, nobody at all to looove itquestion 2)what will happen when you attempt to compile and run this code?public class mymain{public static void main(String argv){System.out.println("hello cruel world");}}1) the compiler will complain that main is a reserved word and cannot be used for a class2) the code will compile and when run will print out "hello cruel world"3) the code will compile but will complain at run time that no constructor is defined4) the code will compile but will complain at run time that main is not correctly definedquestion 6)what will happen when you attempt to compile and run this code?class base{public final void amethod(){System.out.println("amethod");}}public class fin extends base{public static void main(String argv[]){base b = new base();b.amethod();}}1) compile time error indicating that a class with any final methods must be decl ared final itself2) compile time error indicating that you cannot inherit(继承) from a class with final methods3) run time error indicating that base is not defined as final4) success in compilation and output of "amethod" at run timequestion 8)what will happen when you attempt to compile and run this code?private class base{}public class vis{transient int ival;public static void main(String elephant[]){}}1)compile time error: base cannot be private2)compile time error indicating that an integer cannot be transient3)compile time error transient not a data type4)compile time error malformed main methodquestion 9)what happens when you attempt to compile and run these two files in the same directory?//file p1.javapackage mypackage;class p1{void afancymethod(){system.out.println("what a fancy method");}}//file p2.javapublic class p2 extends p1{public static void main(String argv[]){p2 p2 = new p2();p2.afancymethod();}}1) both compile and p2 outputs "what a fancy method" when run2) neither will compile3) both compile but p2 has an error at run time4) p1 compiles cleanly but p2 has an error at compile timequestion 10)you want to find out the value of the last element of an array. you write the following code. what will happen when you compile and run it.?public class myar{public static void main(String argv[]){int[] i = new int[5];System.out.println(i[5]);}}1) an error at compile time2) an error at run time3) the value 0 will be output4) the string "null" will be outputquestion 18)what will happen when you attempt to compile and run the following code?public class bground extends thread{public static void main(string argv[]){bground b = new bground();b.run();}public void start(){for (int i = 0; i <10; i++){system.out.println("value of i = " + i);}}}1) a compile time error indicating that no run method is defined for the thread class2) a run time error indicating that no run method is defined for the thread class3) clean compile and at run time the values 0 to 9 are printed out4) clean compile but no output at runtimequestion 25)what will happen when you attempt to compile and run the following codepublic class hope{public static void main(String argv[]){hope h = new hope();}protected hope(){for(int i =0; i <10; i ++){System.out.println(i);}}}1) compilation error: constructors cannot be declared protected2) run time error: constructors cannot be declared protected3) compilation and running with output 0 to 104) compilation and running with output 0 to 9question 26)what will happen when you attempt to compile and run the following codepublic class myswitch{public static void main(String argv[]){myswitch ms= new myswitch();ms.amethod();}public void amethod(){int k=10;switch(k){case 10:system.out.println("ten");case 20:system.out.println("twenty");break;default:system.out.println("this is the default output");break;}}}1) none of these options2) compile time error target of switch must be an integral type3) compile and run with output "this is the default output"4) compile and run with output of the single line "ten"question 28)what will happen when you attempt to compile and run the following codepublic class as{int i = 10;int j;char z= 1;boolean b;public static void main(String argv[]){as a = new as();a.amethod();}public void amethod(){System.out.println(j);System.out.println(b);}}1) compilation succeeds and at run time an output of 0 and false2) compilation succeeds and at run time an output of 0 and true3) compile time error b is not initialised4) compile time error z must be assigned a char valuequestion 29)what will happen when you attempt to compile and run the following code with the command line "hello there"public class arg{string[] myarg;public static void main(string argv[]){myarg=argv;}public void amethod(){System.out.println(argv[1]);}}1) compile time error2) compilation and output of "hello"3) compilation and output of "there"4) none of the abovequestion 30)what will happen when you attempt to compile and run the following codepublic class streq{public static void main(string argv[]){streq s = new streq();}private streq(){string s = "marcus";string s2 = new string("marcus");if(s = = s2){system.out.println("we have a match");}else{system.out.println("not equal");}}}1) compile time error caused by private constructor2) output of "we have a match"3) output of "not equal"4) compile time error by attempting to compare strings using == question 31)what will happen when you attempt to compile and run the following codeimport java.io.*;class base{public void amethod()throws filenotfoundexception{}}public class excepdemo extends base{public static void main(string argv[]){excepdemo e = new excepdemo();}public void amethod(){}protected excepdemo(){try{datainputstream din = new datainputstream(system.in);system.out.println("pausing");din.readbyte();system.out.println("continuing");this.amethod();}catch(ioexception ioe) {}}}1) compile time error caused by protected constructor2) compile time error caused by amethod not declaring exception3) runtime error caused by amethod not declaring exception4) compile and run with output of "pausing" and "continuing" after a key is hitquestion 32)what will happen when you attempt to compile and run this programpublic class outer{public string name = "outer";public static void main(string argv[]){inner i = new inner();i.showname();}//end of mainprivate class inner{string name =new string("inner");void showname(){system.out.println(name);}}//end of inner class}1) compile and run with output of "outer"2) compile and run with output of "inner"3) compile time error because inner is declared as private4) compile time error because of the line creating the instance of innerquestion 34)which option most fully describes will happen when you attempt to compile and run the following codepublic class myar{public static void main(string argv[]) {myar m = new myar();m.amethod();}public void amethod(){static int i;system.out.println(i);}}1) compilation and output of the value 02) compile time error because i has not been initialized3) compilation and output of null4) compile time errorquestion 35)which of the following will compile correctly1)short myshort = 99s;2) string name = 'excellent tutorial mr green';3) char c = 17c;4)int z = 015;question 38)given the following main method in a class called cycle and a command line of java cycle one twowhat will be output?public static void main(string bicycle[]){system.out.println(bicycle[0]);}1) none of these options2) cycle3) one4) twoquestion 41)given the following codeclass base{}public class mycast extends base{static boolean b1=false;static int i = -1;static double d = 10.1;public static void main(string argv[]){mycast m = new mycast();base b = new base();//here}}which of the following, if inserted at the comment //here will allow the code to compile and run without error1) b=m;2) m=b;3) d =i;4) b1 =i;question 45)what will happen when you attempt to compile and run the following codeint output=10;boolean b1 = false;if((b1= =true) && ((output+=10)==20)){system.out.println("we are equal "+output);}else{system.out.println("not equal! "+output);}1) compile error, attempting to peform binary comparison on logical data type2) compilation and output of "we are equal 10"3) compilation and output of "not equal! 20"4) compilation and output of "not equal! 10"question 48)given the following variableschar c = 'c';int i = 10;double d = 10;long l = 1;string s = "hello";which of the following will compile without error?1)c=c+i;2)s+=i;3)i+=s;4)c+=s;question 51)given the following code what will be the output?class valhold{public int i = 10;}public class obparm{public static void main(string argv[]){obparm o = new obparm();o.amethod();}public void amethod(){int i = 99;valhold v = new valhold();v.i=30;another(v,i);system.out.print( v.i );}//end of amethodpublic void another(valhold v, int i){i=0;v.i = 20;valhold vh = new valhold();v = vh;system.out.print(v.i);system.out.print(i);}//end of another}1) 100302) 200303) 2099304) 10020question 53)given the following class definition which of the following can be legally placed after the comment line//here ?class base{public base(int i){}}public class myover extends base{public static void main(string arg[]){myover m = new myover(10); }myover(int i){super(i);}myover(string s, int i){this(i);//here}}1)myover m = new myover();2)super();3)this("hello",10);4)base b = new base(10);。