JavaCore Test 3 What is the name of the Collection interface used to represent elements in a sequence (in a particular order). Collection Set List Map Which of these classes implement the Collection interface SortedMap. TreeMap Hashtable HashSet HashMap Which statement is true? LinkedList is a subclass of ArrayList Vector is a subclass of Stack HashTable is a sub class of Dictionary ArrayList is a sub class of Vector What happens when the following program is compiled and run. public class example { int i[] = {0}; public static void main(String args[]) { int i[] = {1}; change_i(i); System.out.println(i[0]); } public static void change_i(int i[]) { int j[] = {2}; i = j; } } The program prints 4 The program prints 2 The program prints 1 The program prints 0 Which all lines are part of the output when the following code is compiled and run. Select the three correct answers. public class test { public static void main(String args[]) { outer : for(int i = 0; i = 0; j--) { if(i == j) break outer; System.out.println(i + " " + j); } } } } a. 0 0 b. 0 1 c. 0 2 d. 0 3 e. 1 0 b, d, e c, e, a b, c, d a, b, c Which of these statements is true? AbstractSet extends Set HashSet extends AbstractSet WeakHashMap extends HashMap LinkedList extends List Which of the following are true about interfaces. a. Methods declared in interfaces are implicitly private. b. Variables declared in interfaces are implicitly public, static, and final. c. An interface can extend any number of interfaces. d. The keyword implements indicate that an interface inherits from another. a, b c, d b, d b, c Assume that class A extends class B, which extends class C. Also all the three classes implement the method test(). How can a method in a class A invoke the test() method defined in class C (without creating a new instance of class C). It is not possible to invoke test() method defined in C from a method in A. C.test(); super.test(); test(); By which class we can read object from stream? Reader ObjectInputStream ObjectReader File By using which modifier we can prevent from overridden? final static by default it provides we cant prevent Which are true in case of interface? we can create object implementation to an interface we instantiate an interface directly we can mark interface as final all type of modifiers are allowed to an interface What gets written on the screen when the following program is compiled and run. public class test { public static void main(String args[]) { int i; float f = 2.3f; double d = 2.7; i = ((int)Math.ceil(f)) * ((int)Math.round(d)); System.out.println(i); } } 9 4 6 5 Which of these statements are true. Select the two correct answers. a. For each try block there must be at least one catch block defined. b. A try block may be followed by any number of finally blocks. c. A try block must be followed by at least one finally or catch block. d. If both catch and finally blocks are defined, catch block must precede the finally block. a, c b, d c, d a, b What is the result of compiling and running the following program. public class test { public static void main(String args[]) { String str1="abc"; String str2="def"; String str3=str1.concat(str2); str1.concat(str2); System.out.println(str1); } } def abcabc abcdef abc What are the things we have to follow while creating annotations? methods must not have any throws clauses method should return any one of primitive data types methods must not have any parameters All the above Why we use @Override annotation? To say to the compiler not to execute this override method. To say to compiler that this method is deprecated To check whether the subclass method is overrides from the superclass or not None of the above When we go for thread synchronization? when we want to prevent any other multiple thread to act an same object to make a thread in sleep mode when there is a single thread to remove the lock on the thread Why @SupressWarning Annotation is used? To show exceptions To show warnings To suppress exception issued by compiler What happens if sleep() and wait() executes in synchronized block? Sleep() and wait(),for both the method lock is removed sleep() still under lock ,wait() the lock is removed sleep() the lock is removed ,wait() still under lock The object still under lock in both the cases Which are true among below cases? If programmer want to use several threads then he have to use StringBuffer String class is immutable, StringBuffer and StringBuilder are mutable StringBuffer Class is synchronized and StringBuilder is not synchronized All the above Schreibe einen Kommentar Antworten abbrechenDu musst angemeldet sein, um einen Kommentar abzugeben.