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

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 {

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 ?


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.


}
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


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

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.

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


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status