java基本试题.doc_第1页
java基本试题.doc_第2页
java基本试题.doc_第3页
java基本试题.doc_第4页
java基本试题.doc_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

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

文档简介

重点题型:死记 12/12内嵌类Inner Class)1.内嵌类可以访问outer类的任何变量,包括私有的.2.静态inner类,只能访问outer类的任何static变量2.1内嵌类可以是final,abstract的3.方法内的内嵌类不能为static: void test() static class A XXXXX!4.方法内的内嵌类也不能带任何modifier,void test() public class A XXXXX!5.方法内的内嵌类只能访问方法内的final变量,但是,可以访问outer类的任何变量.6.匿名类不能有构造器,但声明时候带参数,相当于构造器的参数传递.class ABCclass ABCDprivate ABCD(int i)ABC test3()return new ABC();ABCD test4()return new ABCD(3);interface iiiiii test5()return new iii();/class BCD extends ABCD compile error,因为,看上面就知道,new iii();实际上匿名类实现了iii接口;new ABC();实际上是匿名类继承了ABC.8.? class A private A()System.out.println(a!);class B extends A没错!B实例的时候会主动调用父类A的构造,即使是private的,看来也没问题!9.内部类可以有synchronized方法,那么锁是这个内部类,跟外部类没一点关系,内外分别的,在锁的问题上.10.外部类不能通过this被访问,this这时候应该指的是内部类,享用外部类的成员就直接用,不用加任何限定词11.如何用this呢?请看:class Outer int i;class Innerclass InnerInnervoid Test()Outer.this.i=1;看见了吧,类名.this.变量名,可以引用到i,12.注意这两种写法都可以Class Outer.Inner i = new Outer().new Inner();或者, Class o= new Outer(); Class Outer.Inner i=o.new Inner(); ll 总结1、l Which is not a method of the class InputStream?A. int read(byte)B. void flush()C. void close()D. int available()答案:(b)题目:下面哪个不是InputStream类中的方法这个题目没有什么好说的,要求熟悉java API中的一些基本类,题目中的InputStream是所有输入流的父类,所有要很熟悉,参看JDK的API文档。方法void flush()是缓冲输出流的基本方法,作用是强制将流缓冲区中的当前内容强制输出。l Which class is not subclass of FilterInputStream?A. DataInputStreamB. BufferedInputStreamC. PushbackInputStreamD. FileInputStream(d)题目:哪个不是FilterInputStream的子类。此题也是要求熟悉API基础类。Java基础API中的FilterInputStream 的已知子类有:BufferedInputStream, CheckedInputStream, CipherInputStream, DataInputStream, DigestInputStream, InflaterInputStream, LineNumberInputStream, ProgressMonitorInputStream, PushbackInputStream 。l Which classes can be used as the argument of the constructor of the class FileInputStream?A. InputStreamB. FileC. FileOutputStreamD. String答案:(bd)题目:哪些类可以作为FileInputStream类的构造方法的参数。此题同样是要求熟悉基础API,FileInputStream类的构造方法有三个,可接受的参数分别是:File、FileDescriptor、String类的一个对象。l Which classes can be used as the argument of the constructor of the class FilterInputStream?A. FilterOutputStreamB. FileC. InputStreamD. RandomAccessFile答案:(c)题目:哪些类可以作为FilterInputStream类的构造方法的参数。FilterInputStream的构造方法只有一个,其参数是一个InputStream对象。l Which statements about thread are true?A. Once a thread is created, it can star running immediately.B. To use the start() method makes a thread runnable, but it does not necessarily start immediately.C. When a thread stops running because of pre-emptive, it is placed at the front end of the runnable queue.D. A thread may cease to be ready for a variety of reasons.(bd)题目:有关线程的哪些叙述是对的。A. 一旦一个线程被创建,它就立即开始运行。B. 使用start()方法可以使一个线程成为可运行的,但是它不一定立即开始运行。C. 当一个线程因为抢先机制而停止运行,它被放在可运行队列的前面。D. 一个线程可能因为不同的原因停止(cease)并进入就绪状态。一个新创建的线程并不是自动的开始运行的,必须调用它的start()方法使之将线程放入可运行态(runnable state),这只是意味着该线程可为JVM的线程调度程序调度而不是意味着它可以立即运行。线程的调度是抢先式的,而不是分时间片式的。具有比当前运行线程高优先级的线程可以使当前线程停止运行而进入就绪状态,不同优先级的线程间是抢先式的,而同级线程间是轮转式的。一个线程停止运行可以是因为不同原因,可能是因为更高优先级线程的抢占,也可能是因为调用sleep()方法,而即使是因为抢先而停止也不一定就进入可运行队列的前面,因为同级线程是轮换式的,它的运行可能就是因为轮换,而它因抢占而停止后只能在轮换队列中排队而不能排在前面。l The method resume() is responsible for resuming which threads execution?A. The thread which is stopped by calling method stop()B. The thread which is stopped by calling method sleep()C. The thread which is stopped by calling method wait()D. The thread which is stopped by calling method suspend()答案:(d) 题目:方法resume()负责恢复哪些线程的执行。A. 通过调用stop()方法而停止的线程。 B. 通过调用sleep()方法而停止运行的线程。 C. 通过调用wait()方法而停止运行的线程。 D. 通过调用suspend()方法而停止运行的线程。Thread的API文档中的说明是该方法恢复被挂起的(suspended)线程。该方法首先调用该线程的无参的checkAccess() 方法,这可能在当前线程上抛出SecurityException 异常,如果该线程是活着的(alive)但是被挂起(suspend),它被恢复并继续它的执行进程。l 29. class A implements Runnable int i; public void run() try Thread.sleep(5000); i=10; catch(InterruptException e) public static void main(String args) try A a=new A(); Thread t=new Thread(a); t.start(); 17) int j=a.i; 19) catch(Exception e) what be added at line line 17,ensure j=10 at line 19? A. a.wait(); B. t.wait(); C. t.join(); D.t.yield(); E.t.notify(); F. a.notify(); G.errupt(); 答案:Cl 30. Given an ActionEvent, how to indentify the affected component? A.getTarget(); B.getClass(); C.getSource(); D.getActionCommand(); 答案:Dl 33. How to calculate cosine 42 degree? 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); E.double d=Math.toRadious(42); 答案:Cl public class Test 2) public static void main(String args) 3) unsigned byte b=0; 4) b-; 5) 6) 7) what is the value of b at line 5? A.-1 B.255 C.127 D.compile fail E.compile succeeded but run error 答案:Dl public class Test static void leftshift(int i, int j) i=j; public static void main(String args) int i=4, j=2; leftshift(i,j); System.out.println(i); what is the result? 答案:4l 52. which interface Hashtable implements? A. java.util.Map B. java.util.List C. java.util.Hashable D. java.util.Collection 答案:al 146. Which two interfaces provide the capability to store objects using a key-value pair? (Choose Two) A. java.util.MapB. java.util.SetC. java.util.ListD. java.util.StoredSetE. java.util.StoredMapF. java.util.Collection答案:AE147. Which interface does java.util.Hashable implement?A. java.util.MapB. java.util.ListC. java.util.HashableD. java.util.Collection答案:Al 60. Which two CANNOT directly cause a thread to stop executing? (Choose Two)A.Existing(现有) from a synchronized(同步) blockB.Calling the wait method on an objectC.Calling notify method on an objectD.Calling read method on an InputStream objectE.Calling the SetPriority method on a Thread object答案:ACl 61. Click the exhibit button:1. public class SyncTest 2. public static void main(String args) 3. final StringBuffer s1= new StringBuffer(); 4. final StringBuffer s2= new StringBuffer(); 5. new Thread () 6. public void run() 7. synchronized(s1) 8. s2.append(“A”); 9. synchronized(s2) 10. s2.append(“B”); 11. System.out.print(s1); 12. System.out.print(s2); 13. 14. 15. 16. .start(); 17. new Thread() 18. public void run() 19. synchronized(s2) 20. s2.append(“C”); 21. synchronized(s1) 22. s1.append(“D”); 23. System.out.print(s2); 24. System.out.print(s1); 25. 26. 27. 28. .start(); 29. 30. Which two statements are true? (Choose Two) A. The program prints “ABBCAD”B. The program prints “CDDACB”C. The program prints “ADCBADBC”D. The output is a non-deterministic point because of a possible(可能发生)deadlock(死锁)conditionE. The output is dependent on the threading model of the system the program is running on.答案:DEl 64. Which code determines the int value foo closest to(接近), but not greater(包括) than, a double value bar?A. int foo = (int) Math.max(bar);B. int foo = (int) Math.min(bar);C. int foo = (int) Math.abs(bar);D. int foo = (int) Math.ceil(bar);E. int foo = (int) Math.floor(bar);F. int foo = (int) Math.round(bar); 答案:El 66. Given an ActionEvent, which method allows you to identify(识别) the affected(受影响) Component(组成)?A. public class getClass()B. public Object getSource()C. public Component getSource()D. public Component getTarget()E. public Component getComponent()F. public Component getTargetComponent()答案:Bl 67. Click the exhibit button:1. import java.awt.*; 2. 3. public class Test extends Frame 4. public Test() 5. add(new Label(“Hello”) ); 6. add(new TextField(“Hello”) ); 7. add(new Button(“Hello”) ); 8. pack(); 9. show(); 10. 11. 12. public static void main(String args) 13. new Test (); 14. 15. ) What is the result?A. The code will not compile.B. A Window will appear containing only a Button.C. An IllegalArgumentException is thrown at line 6.D. A Window button will appear but will not contain the Label, TextField, or Button.E. A Window will appear containing a Label at the top, a TextField below the Label, and a Button below the TextField. F. A Window will appear containing a Label on the left, a TextField to the right of the Label, and a button to the right of the TextField.答案:Bl 70. Which statement about static inner classes is true?A. An anonymous class can be declared as static.B. A static inner class cannot be a static member of the outer classC. A static inner class does not require an instance of the enclosing class.D. Instance members of a static inner class can be referenced using the class name of the static inner class.答案:C 静态内部类被实例化于外部。l 76. Click the exhibit button. ClassOne.java 1. package com.abc.pkg1; 2. public class ClassOne 3. private char var = a; 4. char getVar() return var; 5. ClassTest.java 1. package com.abc.pkg2; 2. import com.abc.pkg1.ClassOne; 3. public class ClassTest extends ClassOne 4. public static void main(Stringargs) 5. char a = new ClassOne().getVar(); 6. char b = new ClassTest().getVar(); 7. 8. What is the result?A. Compilation will fail.B. Compilation succeeds and no exceptions are thrown.C. Compilation succeeds but an exception is thrown at line 5 in ClassTest.java.D. Compilation succeeds but an exception is thrown at line 6 in ClassTest.java.答案:B private不能被子类访问,但实例化后可访问。l 例题6: Which two statements are true for the class java.util.TreeSet? (Choose two) A. The elements in the collection are ordered. B. The collection is guaranteed to be immutable. C. The elements in the collection are guaranteed to be unique. D. The elements in the collection are accessed using a unique key. E. The elements in the collection are guaranteed to be synchronized 解答:A, C 点评:TreeSet类实现了Set接口。Set的特点是其中的元素惟一,选项C正确。由于采用了树形存储方式,将元素有序地组织起来,所以选项A也正确。l What happens when you try to compile and run the following application? Choose all correct options. 1. public class Z 2. public static void main(String args) 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”); 13. 14. catch (InterruptedException e) 15. System.out.println(“INTERR UPTED”); 16. 17. catch (Exception e) 18. System.out.println(“OTHER EXCEPTION”); 19. 20. finally 21. System.out.println (“FINALLY”); 22. 23. 24. System.out.println(“ALL DONE”); 25. 26. A. The application compiles but doesnt print anything. B. The application compiles and print “DONE WAITING” C. The application compiles and print “FINALLY” D. The application compiles and print “ALL DONE” E. The application compiles and print “INTERRUPTED” 解答:A 点评:在Java中,每一个对象都有锁。任何时候,该锁都至多由一个线程控制。由于alias1与alias2指向同一对象Z,在执行第11行前,线程拥有对象Z的锁。在执行完第11行以后,该线程释放了对象Z的锁,进入等待池。但此后没有线程调用对象Z的notify()和notifyAll()方法,所以该进程一直处于等待状态,没有输出。l 122. How can you create a listener class that receives events when the mouse is moved?A.By extending MouseListener.B.By implementing MouseListener.C.By extending MouseMotionListener.D.By implementing MouseMotionListener.E.Either by extending MouseMotionListener or extending MouseListener.F.Either by implementing MouseMotion Listener or implementing MouseListener.答案:Dl 136. Which constructs a DataOutputStream?A. new dataInputStream(“in.txt”);B. new dataInputStream(new file(“in.txt”);C. new dataInputStream(new writer(“in.txt”);D. new dataInputStream(new FileWriter(“in.txt”);E. new dataInputStream(new InputStream(“in.txt”);F. new dataInputStream(new FileInputStream(“in.txt”);答案:Fl 142. Which two statements are true? (Choose Two) A.An anonymous inner class can be declared inside of a method.A。一个匿名内部类可以声明在一个方法里B.An anonymous inner class constructor can take arguments in some situation.B。一个匿名内部类的构造器一些情况下会引起争议C.An anonymous inner class that is a direct subclass that is a direct subclass of Object can implement multiple interfaces .D.Even if a class Super does not implement any interfaces, it is still possible to define an anonymous inner class that is an immediate subclass of Super that implements a single interface.E.Event if a class Super does not implement

温馨提示

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

评论

0/150

提交评论