SCJP模拟试题.doc_第1页
SCJP模拟试题.doc_第2页
SCJP模拟试题.doc_第3页
SCJP模拟试题.doc_第4页
SCJP模拟试题.doc_第5页
免费预览已结束,剩余15页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

此套试题由60道题组成(实际考试为60道题)。试题由单选题和多选题组成,单选题将提示:Select the one right answer.,多选题将提示:Select all valid answers.。实际考试70%为通过,因此您必须在此套模拟试题中答对42题。Question 1: Given the following class definition:class A protected int i; A(int i) this.i = i; Which of the following would be a valid inner class for this class?Select all valid answers.a)class B b)class B extends A c)class B B() System.out.println(i = + i); d)class B class A e)class A -Question 2: What statements are true concerning the method notify() that is used in conjunction with wait()?Select all valid answers.a) if there is more than one thread waiting on a condition, only the thread that has been waiting the longest is notifiedb) if there is more than one thread waiting on a condition,there is no way to predict which thread will be notifedc) notify() is defined in the Thread classd) it is not strictly necessary to own the lock for the object you invoke notify() fore) notify() should only be invoked from within a while loop-Question 3: Given the following class:class Counter public int startHere = 1; public int endHere = 100; public static void main(String args) new Counter().go(); void go() / A Thread t = new Thread(a); t.start(); What block of code can you replace at line A above so that this program will count from startHere to endHere?Select all valid answers.a)Runnable a = new Runnable() public void run() for (int i = startHere; i = endHere; i+) System.out.println(i); ;b)a implements Runnable public void run() for (int i = startHere; i = endHere; i+) System.out.println(i); ; c)Thread a = new Thread() public void run() for (int i = startHere; i = endHere; i+) System.out.println(i); ;-Question 4: What is written to the standard output given the following statement:System.out.println(4 | 7);Select the one right answer.a) 4b) 5c) 6d) 7e) 0-Question 5: Given the following class:class Counter public static void main(String args) Thread t = new Thread(new CounterBehavior(); t.start(); Which of the following is a valid definition of CounterBehavior that would make Counters main() method count from 1 to 100, counting once per second?Select the one right answer.a)This class is an inner class to Counter:class CounterBehavior for (int i = 1; i = 100; i+); try System.out.println(i); Thread.sleep(1000); catch (InterruptedException x) b) This class is an inner class to Counter:class CounterBehavior implements Runnable public void run() for (int i = 1; i = 100; i+); try System.out.println(i); Thread.sleep(1000); catch (InterruptedException x) c) This class is a top-level class:static class CounterBehavior implements Runnable public void run() try for (int i = 1; i = 100; i+) System.out.println(i); Thread.sleep(1000); catch (InterruptedException x) -Question 6: Given the following class definition:class A public int x; private int y; class B protected void method1() class C private void method2() class D extends A public float z;What can method2() access directly, without a reference to another instance?Select all valid answers.a) the variable x defined in Ab) the variable y defined in Ac) method1 defined in Bd) the variable z defined in D-Question 7: You have an 8-bit file using the character set defined by ISO 8859-8. You are writing an application to display this file in a TextArea. The local encoding is already set to 8859-8. How can you write a chunk of code to read the first line from this file?You have three variables accessible to you:myfile is the name of the file you want to read stream is an InputStream object associated with this file s is a String object Select all valid answers.a)InputStreamReader reader = new InputStreamReader(stream, 8859-8);BufferedReader buffer = new BufferedReader(reader);s = buffer.readLine();b)InputStreamReader reader = new InputStreamReader(stream);BufferedReader buffer = new BufferedReader(reader);s = buffer.readLine();c)InputStreamReader reader = new InputStreamReader(myfile, 8859-8);BufferedReader buffer = new BufferedReader(reader);s = buffer.readLine();d) InputStreamReader reader = new InputStreamReader(myfile);BufferedReader buffer = new BufferedReader(reader);s = buffer.readLine();e)FileReader reader = new FileReader(myfile);BufferedReader buffer = new BufferedReader(reader);s = buffer.readLine();-Question 8: How can you write a line of code for an applets init() method that determines how wide the applet is?Select all valid answers.a) int width = this.getY();b) int width = this.getSize().w;c) int width = getSize();d) int width = getSize().w;e) int width = getWidth();-Question 9: For a variable width font, how wide is a TextField created using the expression:new TextField(20)Select the one right answer.a) 20 times the average of all the characters in the font used for this TextField objectb) 20 times the width of the letter Mc) 20 times the width of the letter ad) 20 inchese) 20 picas-Question 10: Given this interface definition:interface A int method1(int i); int method2(int j);which of the following classes implement this interface and is not abstract?Select all valid answers.a)class B implements A int method1() int method2() b)class B int method1(int i) int method2(int j) c)class B implements A int method1(int i) int method2(int j) d)class B extends A int method1(int i) int method2(int j) e)class B implements A int method2(int j) int method1(int i) -Question 11: Given the following code:import java.awt.*;import java.awt.event.*;public class MyApplet extends java.applet.Applet public void init() Button b = new Button(Button1); b.addMouseListener(new ClickHandler(); add(b); class ClickHandler extends MouseAdapter public void mouseClicked(MouseEvent evt) / A What line of code at A writes the mouses horizontal location to the standard output at the time of the event? Fill in the blank.-Question 12: Given the same code as in question 10, how can you write a line of code at A that will place the Button object into a variable named mybutton that is already defined to be a reference to a Button object?Fill in the blank.-Question 13: Which Listener interface can you implement to be able to respond to the user hitting the enter key after typing into a TextField object?Fill in the blank.-Question 14: What is written to the standard output as the result of executing the following statements?Boolean b1 = new Boolean(true);Boolean b2 = new Boolean(true);if (b1 = b2) if (b1.equals(b2) System.out.println(a); else System.out.println(b);else if (b1.equals(b2) System.out.println(c); else System.out.println(d);Select the one right answer.a) ab) bc) cd) d-Question 15: Which Listener interfaces can you add to a TextArea object?a) TextListenerb) ActionListenerc) MouseMotionListenerd) MouseListenere) ComponentListener-Question 16: What appears in the standard output if the method named problem() in the code below throws an instance of class Exception when the method named trythis() is invoked?public void trythis() try System.out.println(1); problem(); catch (RuntimeException x) System.out.println(2); return; catch (Exception x) System.out.println(3); return; finally System.out.println(4); System.out.println(5);Select all valid answers. a) 1b) 2c) 3d) 4e) 5-Question 17: What is the type of the Event object passed to the mouseDragged() method defined in a class that implements java.awt.event.MouseMotionListener (that is, what is the class name for the argument)?Fill in the blank.-Question 18: Examine the following switch block:char mychar = c;switch (mychar) default: case a: System.out.println(a); break; case b: System.out.println(b); break;Which of the following questions are definitely true?Select all valid answers.a) This switch block is illegal, because only integers can be used in the switch statement.b) This switch block is fine.c) This switch block is illegal, because the default statement must come last.d) When this code runs, nothing is written to the standard output.e) When this code runs, the letter a is written to the standard output.-Question 19: What keyword must appear in a method declaration (followed by the name of the exception) when that method might cause an exception to be thrown and that method does not handle the exception?Fill in the blank.-Question 20: Which statements accurately describe the following line of code?Select all valid answers.String s = new String10;a) This line of code is illegal.b) s is a two-dimensional array containing 10 rows and 10 columnsc) s is an array of 10 arrays.d) Each element in s is set to e) Each element in s is uninitialized and must be initialized before it is referenced.Question 21: What will happen if you try to compile and run the following class?class Test static int myArg = 1; public static void main(String args) int myArg; System.out.println(myArg); Select the one right answer.a) This code compiles and displays 0 in the standard output when run.b) This code compiles and displays 1 in the standard output when run.c) This code does not compile because you cannot define a local variable named the same as a static variable.d) This code does not compile because the local variable is used before it is initialized.-Question 22: Which declarations for the main() method in a stand-alone program are NOT valid?Select all valid answers.a) public static void main()b) public static void main(String string)c) public static void main(String args)d) static public int main(String args)e) static void main(String args)-Question 23: Which of the following identifiers are ILLEGAL?Select all valid answers.a) #_poundb) _underscorec) 5Interstated) Interstate5e) _5_-Question 24: If the user invokes a stand-alone application by typing:java YourApp 1 2 3and the main() method defines its String parameter as args, how can you access the number 2 using args?Fill in the blank.-Question 25: Which interface implementations can you add as listeners for a TextField object?Select all valid answers.a) ActionListenerb) FocusListenerc) MouseMotionListenerd) WindowListenere) ContainerListener-Question 26: What must be true for the RunHandler class so that instances of RunHandler can be used as written in the code below:class Test public static void main(String args) Thread t = new Thread(new RunHandler(); t.start(); Select all valid answers. a) RunHandler must implement the java.lang.Runnable interface.b) RunHandler must extend the Thread class.c) RunHandler must provide a run() method declared as public and returning void.d) RunHandler must provide an init() method.-Question 27: To determine if you can invoke addContainerListener() for a component referenced using a variable named c, which expression(s) can you evaluate that will give you a true or false answer to this questions?Select all valid answers.a) c = Containerb) c.equals(Class.Container)c) c instanceof Containerd) c instanceof Componente) c implements Container-Question 28: Write a statement for a constructor that invokes the no-args, default constructor in its superclass.Fill in the blank.-Question 29: What is written to the standard output given the following statement:System.out.println(4 & 7);Select the one right answer.a) 4b) 5c) 6d) 7e) 0-Question 30: What will the following block of code write to the standard output when it is executed?int i = 3;int j = 0;double k = 3.2;if (i k) if (i = j) System.out.println(i); else System.out.println(j);else System.out.println(k);Select the one right answer.a) 3b) 0c) 3.2d) none of these-Question 31: How can you use the String method indexOf() to determine which position the letter C is in given this String:String s = ABCDE;Write a complete statement in your answer, but you do not have to assign the letter you retrieve to another variable. Fill in the blank.-Question 32: Given that the variable g references a valid Graphics object, what does the following statement do?g.fillRect(2, 3, 10, 20);Select all valid answers.a) draw the outline of a rectangle in the current background colorb) draw the outline of a rectangle in the current foreground colorc) fill in a rectangle using the current background colord) fill in a rectangle using the current foreground colore) fill in a rectangle in black-Question 33: Describe the following applet.import java.applet.Applet;import java.awt.event.*;import java.awt.*;public class MyApplet extends Applet Button b1, b2; public void init() ActionListener a = new ActionListener() public void actionPerformed(ActionEvent evt) if (evt.getSource() = b1) b1.setEnabled(false); b2.setEnabled(true); else b1.setEnabled(true); b2.setEnabled(false); ; b1 = new Button(1); b1.addActionListener(a); add(b1); b2 = new Button(2); b2.addActionListener(a); add(b2); Select all valid answers.a) Nothing appears in the appletb) One button a

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论