Đề thi lý thuyết môn java programing trong aptech

10 3.1K 1
Đề thi lý thuyết môn java  programing trong aptech

Đang tải... (xem toàn văn)

Thông tin tài liệu

1 : Which of the following statements is true ? A. A deadlock situation will not occur if the wait() / notify() mechanism is used B. Both the wait () and sleep() can throws a runtime exception . C. The wait() method can be overloaded to accept a duration . D. Both wait() and notify() methods can be called from an unsynchronized context 2 : Which will be the result of trying to compile and run the Expression : (Math.random()*4) ? A. A negative number might be returned . B. The number 0 will be returned . C. The probability that the number 0,1,2 or 3 might be returned is equal D. The number 4 is returned . 3 : Which of the following fields or methods does not belong to the File class ? A. getParent() B. separator C. dirname D. getName() 4 : Which is the most suitable data-structure to store small amount of the data for rapid access that need not be sorted or checked for uniqueness? A. TreeSet B. HashMap C. LinkedList D. an array 5 : Which expression will extract the substring "cas" from the string defined by String ="cacaso"? A. str.substring(2,2) B. str.substring(2,3) C. str.substring(3,2) D. str.substring(2,5) 6 : What will be the result of trying to compile and run the following code ? public class MyClass { public static void main(String[] args){ StringBuffer sb = new StringBuffer("have a nice day"); sb.setLength(6); System.out.println(sb); } } A. The code will fail to compile since there is no method named setLength() in the StringBuffer B. The program will print "have a" when run C. The program will print "ce day" when run D. The program will print "have a nice day" when run 7 : What will be the result of trying to compile and run the following code ? import java.io.*; class MyInput { public static void main(String[] args){ MyInput objInput = new MyInput(); objInput.go(); } public void go() { try { DataInputStream dis = new DataInputStream(System.in); dis.read(); } catch(Exception e) {} System.out.println ("Continue."); } } A. The code will run and pause until a key is hit B. The code will not compile because System.in is a static class. C. The code will compile and run to completion without output D. The code will not compile because System.in is not a valid constructor for DataInputStream. 8 : Which methods of the Matcher class do not actually attempt to match an input sequence against a pattern ? A. matches() B. start() C. find() D. lookingAt() 9 : The following code create a thread using Runnable object . Runnable objRunnable = new MyThread(); Thread t1 = new Thread(objRunnable); Which of the following classes can be used so that the above code compiles correctly ? A. public class MyThread extends Runnable { public void run(){}} B. public class MyThread implements Runnable { public void run(){} } C. public class MyThread extends Object { public void run()} D. public class MyThread implements Runnable{ public void start(){}} 10 : Which of the following would cause a compile time error ? A. Class c = "boolean".getClass(); B. Class c = boolean.getClass(); C. Class c = Boolean.class; D. Class c = Class.forName(java.lang.Interger); 11 : public interface MyInterface { public void doStuff(); } What would be the exception thrown if the following line of code is used in the program ? MyInterface.class.getConstructor(new Class[] {}); A. java.lang.NoSuchMethodException B. java.lang.NoAvailableConstructorException C. java.lang.ClassCastException D. No exception is thrown 12 : What will be the output of the trying to compile and run the following program ? public class Task1 extends Thread { String str; public Task1(String s){str= s}; public void run(){ System.out.println A. The program fails to compile . B. The program compiles and prints Hello and World in that order when it runs . C. The program compiles and prints Hello and World in no pre-determined order . D. The program compiles and terminates without and output when run . 13 : A … method when invoked for an object ,acquires a… for the object before comme . ? A. start(),reference B. run(),lock C. notify(),reference D. syschronized,lock 14 : A thread can be created by extending the Thread class .Which of the following methods are defined in the class Thread ? A. wait(),notify() and run() B. start() and run() C. start(),wait(),notify() and run() D. run() and terminate() 15 : Which of the following statements should be inserted at line 4 so that the following code will compile properly ? Import java.util.*; class MyClass{ public static void man(String[] args{ // line of code to be inserted here x.add("one"); } } A. A.List<String> x = new LinkedList<String>(); B. ArrayList<String> x = new ArrayList<String>(); C. HashSet<String> x = new HashSet<String>(); D. LinkedList<String> x = new LinkedList<String>(); 16 : What is the output of compiling and running the following code ? Interface Storable{ void store(); } class File implements Storable{ @Override Public void store() {} } A. The code compiles and runs normally B. The code compiles but with a warning saying that it uses a deprecated API. C. The compiler gives an error depicting that the File.store() method does not override any method from its superclass . D. The code compiles and gives a warning at runtime. 17 : Which of the following constructors is not a valid constructor for the class declared as follows: class Generics<T>() A. public Generics(){} B. public Generics<T>(){} C. public <T> Generics(T t){} D. public <T> Generics(){} 18 : What will be the output of compiling and running the following code? HashSet<String> hs = new HashSet<String>(); hs.add(“apples”); hs.add(“oranges”); HashSet<Object> s = new HashSet<Object>(); s=hs; System.out.println(s); A. prints [apples, oranges]. B. ClassCastException is thrown at runtime. C. compiler error. D. prints [oranges, apples] 19 : What will be the result of trying to compile and run the following piece of code? public static void doIt(){ Set set = new TreeSet(); set.add(“2”); set.add(3); set.add(“1”); Iterator it = set.iterator(); while(it.hasNext()){ System.out.println(it.next() + “ ”); } } A. The method fails to compile. B. The method will compile with warnings but throw an exception at runtime. C. The method will print three numbers but the order cannot be determined. D. The method will print 1,2. 20 : import java.lang.reflect.*; class Hello { public void sayHello(){ System.out.println ("Hello!"); } } Which statement is incorrect? A. Hello x = (Hello) h.newInstance(); B. Hello x = (Hello) h.getDeclaredConstructor().newInstance(); C. Hello x = (Hello) h.getConstructor().newInstance(); D. None of above 21 : They are extra informations associated with particular section of a document or with the whole document.They provide information about an existing data and can be used with any web document. A. Refletion B. Regular Expression C. Annotation D. Threads 22 : Annotations are comments, notes, explainations, or external remarks attached to a web document. A. True B. False 23 : An Annotation declaration consits of followed by th anotation type (1 choice) A. Data Type B. Character C. @ D. @@ 24 : Which statements are true? (2 Choices) A. Annotation name should begin with @ symbol followed by the keyword interface and the annotation name B. Parameters should be associated with method declarations C. Return type of method declaration should be either primitive, String,enum,Class or array of the above types D. Return type of method declaration should be either boolean, String,enum,Class or array of the above types. E. throws clause may be used with method declarations. 25 : Annotations consist of names and have no value associated with it. It consist of the annotaion name and no additional data. A. Single - Value Annotations. B. Maker Annotations. C. Full Annotations 26 : Be Known as single - element, It consists of single value. It can be represented as data= value pair or value within the parenthese. A. Full Annotations. B. Maker Annotations. C. Single - Value Annotations 27 : It consists of multiple data mambers. Each member should be represented by data=value pair. A. Full Annotations B. Single - Value Annotations C. Maker Annotations. 28 : Annotation can not be used to which items: A. Classes,Package B. Methods,Constructors C. Global variables D. Interfaces,Local Variable 29 : Annoation is used to indicated that the marker element should not be used. The compiler will generate a warning whenever we use this item. A. @Override B. @deprecate C. @Interface D. @suppressWarnings E. @Documented. 30 : This Annotation should not be used on classes, interfaces, package, or constructors. It should be used on method. A. @Deprecated B. @Documented. C. @suppressWarnings D. @Override E. @Interface 31 : This annotaion gives us permission to do selective suppression of warnings within particular code sections. A. @suppressWarnings B. @Documented. C. @Interface D. @Override E. @Retention 32 : The annotation type is used to determine the longevity of the information. A. @Documented B. @Retention C. @Deprecated D. @Override 33 : The use of annotation type indicateds that the markered element should no longer be used. A. @Override B. @Deprecated 34 : Which statements are true? (3 choices) A. Parameters in annotation can be initialized with arrays of values B. Parameters in annotation can have null values C. Parameters in annotation are declared as a fields in a class D. Parameters in annotation types may defne default values for some members E. Parameters in annotation can be initialized to arrays of String values 35 : The reflection API corresponds to classes, Interfaces and objects in JVM. A. True B. False 36 : Which statements are true? (3 choices) A. Reflection API induces code into a particular set of classes during execution B. Reflection API retrieves the object and its interface for examination C. Reflection API cannot manipulate classes. D. Reflection API is used to get and set values in an array E. Reflection API cannot be used to retrieve th constructors, methods and fields in a class. 37 : Which of the following details are not retrieved when a class is examined? A. Class name B. Constructors C. Class Field D. Package Information E. Method Information. 38 : Create objects using default constructors? A. NewInstance() on class B. NewInstance() on Constructor C. getField() on class D. set() E. invoke() 39 : Create objects using prameterized constructors A. invoke() B. getField() on class C. set() D. NewInstance() on Constructor E. NewInstance() on class 40 : Retrieve field values using reflection. A. NewInstance() on Constructor B. invoke() C. getField() on class D. set() E. NewInstance() on class 41 : Assign field values using reflection. A. NewInstance() on Constructor B. getField() on class C. invoke() D. set() E. NewInstance() on class 42 : Invoke methods using refleftion. A. getField() on class B. NewInstance() on Constructo C. invoke() D. set() E. NewInstance() on class 43 : Which statements are true ? (3 choices) A. Array can be identified at runtime. B. Arrays can not be created at runtim C. Values of arrays can be retrieved during runtime D. Values to elements can be assigned to arrays at runtime E. Array objects cannot be instantiated. 44 : This is matched with a character sequence string. This is called as input Sequence. A. Pattern Class B. Matcher Class 45 : Matcher Class does not have any constructors. A. True B. False 46 : This tries to match the entire input sequence against the pattern (1 choice) A. boolean matches() B. boolean find() C. nt end() D. boolean lookingAt() 47 : So as to create a pattern object, method is invoked A. boolean matches() B. compile() C. matcher() D. int start() 48 : tries to match the input sequence against the pattern starting from beginning. A. boolean find() B. boolean lookingAt() 49 : returns the start index of the previous match. A. int start() B. int end() 50 : The following code will give 1: Byte b1 = new Byte("127"); 2: 3: if(b1.toString() = = b1.toString()) 4: System.out.println("True"); 5: else 6: System.out.println("False"); A. Compilation error, toString() is not avialable for Byte. B. Prints "True" C. Prints "False". D. Depends on the particular implementation of the Java Virtual Machine E. Runtime error . ? MyInterface.class.getConstructor(new Class[] {}); A. java. lang.NoSuchMethodException B. java. lang.NoAvailableConstructorException C. java. lang.ClassCastException D. No exception is thrown . compiler will generate a warning whenever we use this item. A. @Override B. @deprecate C. @Interface D. @suppressWarnings E. @Documented. 30 : This Annotation should not be used on classes, interfaces,. @Documented. C. @suppressWarnings D. @Override E. @Interface 31 : This annotaion gives us permission to do selective suppression of warnings within particular code sections. A. @suppressWarnings B. @Documented. C.

Ngày đăng: 03/06/2014, 14:13

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan