JavaCore Test 4 At what stage in the following method does the object initially referenced by s becomes available for garbage collection. void method X() { String r = new String("abc"); String s = new String("abc"); r = r+1; //1 r = null; //2 s = s + r; //3 } //4 Before statement labeled 1 Before statement labeled 2 Before statement labeled 3 Before statement labeled 4 Which of the following statements is preferred to create a string "Welcome to Java Programming"? String str; str = new String ("Welcome to Java Programming") String str; str = "Welcome to Java Programming" String str = new String("Welcome to Java Programming") String str = "Welcome to Java Programming" What all gets printed on the standard output when the class below is compiled and executed by entering "java test lets see what happens". public class test { public static void main(String args[]) { System.out.println(args[0]+" "+args.length); } } a. java b. test c. lets d. 3 e. 4 f. 5 g. 6 c, e b, f a, d f, e In implementing two classes Employee and Manager, such that each Manager is an Employee, what should be the relationship between these classes. Employee class should include Manager class as a data member. Manager class should include the Employee class as a data member. Manager should be the base class of Employee class. Employee should be the base class of Manager class. Which all lines are part of the output when the following code is compiled and run. Select the six correct answers. public class test { public static void main(String args[]) { outer: for(int i = 0; i = 0; j--) { if(i == j) continue outer; System.out.println(i + " " + j); } } } } a. 0 0 b. 0 1 c. 0 2 d. 0 3 e. 1 0 f. 1 1 g. 1 2 h. 1 3 i. 2 0 j. 2 1 k. 2 2 l. 2 3 m. 3 0 n. 3 1 o. 3 2 p. 3 3 c, g, h, l, n, o b, c, d, g, h, l a, b, d, f, h, j d, g, j, k, m, n String s = new String("xyz"); Assuming the above declaration, which of the following statements would compile. s = 2 * s; s = s + s; s = s >> 2; int i = s[0]; Which of the following statements is true? the class Class is the super class of all other classes in Java. class ClassTwo extends ClassOne means ClassTow is a super class class ClassTwo extends ClassOne means ClassOne is a subclass A super class is a sub set of a sub class 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; i = change_i(i); System.out.println(i); } public static int change_i(int i) { i = 2; i *= 2; return i; } } The program prints 0. The program prints 1. The program prints 2. The program prints 4. Select the one most appropriate answer. What is the purpose of method parseInt defined in Integer class. The method converts the Integer object to a String. The method is used to convert String to Integer class, assuming that the String represents an integer. The method is used to convert String to an integer, assuming that the String represents an integer. The method converts an integer to a String. Which of the following statements related to Garbage Collection are correct. a. It is possible for a program to free memory at a given time. b. Garbage Collection feature of Java ensures that the program never runs out of memory. c. It is possible for a program to make an object available for Garbage Collection. d. The finalize method of an object is invoked before garbage collection is performed on the object. b, c c, d b, d a, b What kind of thread is the Garbage collector thread is? Non daemon thread Daemon thread Thread with dead state None of the above 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); } public static void change_i(int i) { i = 2; i *= 2; } } The program prints 4. The program prints 1. The program prints 2. The program prints 0. What should be done to invoke the run() method on a thread for an object derived from the Thread class. The creation of the object using the new operator would create a new thread and invoke its run() method. The init() method should be directly invoked on the Object. The start() method should be directly invoked on the Object. The run() method should be directly invoked on the Object. If a base class has a method defined as void method() { } Which of the following are legal prototypes in a derived class of this class. a. void method() { } b. int method() { return 0;} c. void method(int i) { } d. private void method() { } b, d a, c a, d b, c In which all cases does an exception gets generated. int i = 0, j = 1; a. if((i == 0) || (j/i == 1)) b. if((i == 0) | (j/i == 1)) c. if((i != 0) && (j/i == 1)) d. if((i != 0) & (j/i == 1)) a, d b, d b, c a, c When a thread terminates its processing, into what state that thread enters? Beginning state Running state Waiting state Dead state 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[]) { i[0] = 2; i[0] *= 2; } } The program prints 4. The program prints 2. The program prints 1. The program prints 0. What is the default priority of a newly created thread? A thread inherits the priority of its parent thread. MAX_PRIORITY (which is defined as 10 in the Thread class.) NORM_PRIORITY (which is defined as 5 in the Thread class.) MIN_PRIORITY (which is defined as 1 in the Thread class.) Which of the following statements are true. a. The wait method defined in the Thread class, can be used to convert a thread from Running state to Waiting state. b. The wait(), notify(), and notifyAll() methods must be executed in synchronized code. c. The notify() and notifyAll() methods can be used to signal and move waiting threads to ready-to-run state. d. The Thread class is an abstract class. c, d b, c a, d a, c Which keyword when applied on a method indicates that only one thread should execute the method at a time. native synchronized volatile transient Schreibe einen Kommentar Antworten abbrechenDu musst angemeldet sein, um einen Kommentar abzugeben.