CS-176 Final Exam Study Guide

Ace your homework & exams now with Quizwiz!

Ques 38 : What is the minimum value of char type. Select the one correct answer. (A) 0 (B) -215 (C) -28 (D) -215 - 1

A: 0

Ques 31 : Using up to four characters what is the Java representation of the number 23 in hex? (A) 0x17 (B) 0x18 (C) 0x19 (D) 0x20

A: 0x17

Ques 69 : Which of the following statements are true. Select the one correct answer. (A) Arrays in Java are essentially objects. (B) It is not possible to assign one array to another. Individual elements of array can however be assigned (C) Array elements are indexed from 1 to size of array. (D) If a method tries to access an array element beyond its range, a compile warning is generated.

A: Arrays in Java are essentially objects. Reason: Java supports assignment of one array to another. Hence b is incorrect. Array elements are indexed from 0. Hence c is incorrect. A method that accesses array elements out of its range does not generate a compilation error. Hence d is incorrect.

Ques 5 : A lower precision can be assigned to a higher precision value in Java. For example a byte type data can be assigned to int type. (A) True (B) False

A: True

Ques 21 : Which of these statements are legal. Select the correct answers among the following: a. int arr[][] = new int[5][5]; b. int []arr[] = new int[5][5]; c. int[][] arr = new int[5][5]; d. int[] arr = new int[5][]; e. int[] arr = new int[][5]; (A) a, b (B) a, b, c (C) a, b, c, d (D) a, b, c, d, e

B: a, b, c

Ques 1 : Which declaration of the main method below would allow a class to be started as a standalone program? (A) public static int main(char args[]) (B) public static void main(String args[]) (C) public static void MAIN(String args[]) (D) public static void main(String args)

B: public static void main(String args[])

Ques 73 : Which of these are valid declarations for the main method? Select the one correct answer. (A) public void main(); (B) public static void main(String args[]); (C) static public void main(String); (D) public static int main(String args[]);

B: public static void main(String args[]);

Ques 75 : What is the result of compiling and running the following program. Select one correct answer. public class test { public static void main(String args[]) { int i = -1; i = i >> 1; System.out.println(i); } } (A) 255 (B) 128 (C) -1 (D) 1

C: -1

Ques 64 : What is the result of compiling and running the following program. Select the one correct answer. class test { public static void main(String args[]) { int[] arr = {1,2,3,4}; call_array(arr[0], arr); System.out.println(arr[0] + "," + arr[1]); } static void call_array(int i, int arr[]) { arr[i] = 6; i = 5; } } (A) 1,2 (B) 5,2 (C) 1,6 (D) 5,6

C: 1, 6 Reason: In the invocation of call_array, the first element is invoked using call-by-value, and the second using call-by-reference.

Ques 67 : How many numeric data types are supported in Java? (A) 8 (B) 4 (C) 6 (D) 2

C: 6

Ques 96 : Consider the following code snippet. What will be assigned to the variable fourthChar, if the code is executed? String str = new String("Java"); char fourthChar = str.charAt(4); (A) 'a' (B) 'v' (C) throws StringIndexOutofBoundsException (D) null characater

C: throws StringIndexOutofBoundsException

Ques 56 : What gets displayed on the screen when the following program is compiled and run. Select the one correct answer. public class test { public static void main(String args[]) { int x,y; x = 3 & 5; y = 3 | 5; System.out.println(x + " " + y); } } (A) 7 1 (B) 3 7 (C) 1 7 (D) 1 3

D: 1 3

Ques 58 : Given the following code snippet, what is the value of salaries [3]? int salaries[]; int index = 0; salaries = new int salaries[4]; while (index < 4) { salaries[index] = 10000; index++; } (A) 40000 (B) 50000 (C) 15000 (D) 10000

D: 10000

Ques 65 : What gets displayed on the screen when the following program is compiled and run. Select the one correct answer. public class test { public static void main(String args[]) { int x; x = -3 >> 1; x = x >>> 2; x = x << 1; System.out.println(x); } } (A) 7 (B) 23 (C) 5 (D) 2147483646

D: 2147483646

Ques 34 : What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer. public class ShortCkt { public static void main(String args[]) { int i = 0; boolean t = true; boolean f = false, b; b = (t | ((i++) == 0)); b = (f | ((i+=2) > 0)); System.out.println(i); } } (A) 0 (B) 1 (C) 2 (D) 3

D: 3

Ques 3 : Which of these are legal identifiers? (A) number_1 (B) number_a (C) $1234 (D) All of the above.

D: All of the above

Ques 30 : Using up to four characters, write the Java representation of octal literal 6. (A) 06 (B) 006 (C) 0006 (D) all of above

D: All of the above

Ques 4 : Which of the following are Java keywords? (A) throw (B) void (C) private (D) All of the above.

D: All of the above

Ques 70 : Which of the following are correct. Select all correct answers. (A) Java provides two operators to do left shift - << and <<<. (B) >> is the zero fill right shift operator. (C) >>> is the signed right shift operator. (D) For positive numbers, results of operators >> and >>> are same.

D: For positive numbers, results of operators >> and >>> are the same

Ques 97 : To make a variable defined in a class accessible only to methods defined in the classes in same package, which of the following keyword should be used. Select the one correct answer. (A) By using the keyword public before the variable. (B) By using the keyword protected before the variable. (C) By using the keyword private before the variable. (D) The variable should not be preceded by any of the above mentioned keywords.

D: The variable should not be preceded by any of the above mentioned keywords Reason: A data member that does not have public/protected/private is accessible to all methods in the same package.

Ques 33 : Which of the following are valid constructors within a class Test. Select the correct answers among the following: a. test() { } b. Test() { } c. void Test() { } d. private final Test() { } e. abstract Test() { } f. Test(Test t) { } g. Test(void) { } (A) b, d (B) c, f (C) b, c (D) b, f

D: b, f

Ques 77 : The class java.lang.Exception is ... (A) protected (B) implements Throwable (C) serializable (D) extends Throwable

D: extends Throwable

Ques 44 : Which of the following are true. Select the one correct answers. (A) && operator is used for short-circuited logical AND. (B) ~ operator is the bit-wise XOR operator. (C) operator is used to perform bitwise OR and also short-circuited logical OR. (D) The unsigned right shift operator in Java is >>.

A: && operator is used for short-circuited logical AND.

Ques 91 : What gets printed when the following code is compiled and run. Select the one correct answer. public class test { public static void main(String args[]) { int i = 1; do { i--; } while (i > 2); System.out.println(i); } } (A) 0 (B) 1 (C) 2 (D) -1

A: 0

Ques 43 : Using up to four characters, write the Java representation of integer literal 3 in hexadecimal (A) 0x03, 0X03, 0X3 (B) 0x04, 0X04, 0X4 (C) 0x05, 0X05, 0X5 (D) none of these

A: 0x03, 0X03, 0x3

Ques 60 : What gets printed when the following program is compiled and run. Select the one correct answer. (A) 4 4 8 6 (B) 4 4 8 8 (C) 4 4 6 6 (D) 4 3 8 6

A: 4 4 8 6

Ques 82 : Which of the following statements is true? (A) An exception can be thrown by throw keyword explicitly. (B) An exception can be thrown by throws keyword explicitly.

A: An exception can be throw by throw keyword explicitly

Ques 8 : Which of the following statements about the Java language is true? (A) Both procedural and OOP are supported in Java. (B) Java supports only procedural approach towards programming. (C) Java supports only OOP approach. (D) None of the above.

A: Both procedural and OOP are supportin in Java.

Ques 18 : What gets displayed on the screen when the following program is compiled and run. Select the one correct answer. protected class example { public static void main(String args[]) { String test = "abc"; test = test + test; System.out.println(test); } } (A) The class does not compile because the top level class cannot be protected. (B) The program prints "abc" (C) The program prints "abcabc" (D) The program does not compile because statement "test = test + test" is illegal.

A: The class does not compile because the top level class cannot be protected

Ques 83 : What happens when the following program is compiled and executed with the command - java test. Select the one correct answer. class test { public static void main(String args[]) { if(args.length > 0) System.out.println(args.length); } } (A) The program compiles and runs but does not print anything. (B) The program compiles and runs and prints 0 (C) The program compiles and runs and prints 1 (D) The program compiles and runs and prints 2

A: The program compiles and runs but does not print anything

Ques 13 : Which of these are legal identifiers. Select all potential correct answers among the following: a. number_1 b. number_a c. $1234 d. -volatile (A) a, b, c (B) a, b (C) a (D) b

A: a, b, c

Ques 78 : Which of the following are valid declarations for the main method. Select the three correct answers. a. public static void main(String args[]); b. public static void main(String []args); c. final static public void main (String args[]); d. public static int main(String args[]); e. public static abstract void main(String args[]); (A) a, b, c (B) b, d, e (C) a, d, c (D) a, b, e

A: a, b, c

Ques 51 : Which of the following are true. Select the correct answers from the following: (A) a,b,c (B) a,b (C) b,c,d (D) all of above

A: a, b, c Reason: final modifier may appear before a method, a variable, or before a class

Ques 87 : All the wrapper classes (Integer, Boolean, Float, Short, Long, Double and Character) in java... (A) are final (B) are private (C) are serializable (D) are immutatable

A: are final

Ques 16 : Given a one dimensional array arr, what is the correct way of getting the number of elements in arr. Select the one correct answer. (A) arr.length (B) arr.length - 1 (C) arr.size (D) arr.length()

A: arr.length

Ques 63 : Which of the following statements are correct. Select the four correct answers. a. A Java program must have a package statement. b. A package statement if present must be the first statement of the program (barring any comments). c. If a Java program defines both a package and import statement, then the import statement must come before the package statement. d. An empty file is a valid source file. e. A Java file without any class or interface definitions can also be compiled. f. If an import statement is present, it must appear before any class or interface definitions. (A) b, d, e, f (B) a, b, d, f (C) d, e, a, c (D) c, d, b, a

A: b, d, e, f

Ques 10 : Which of these are legal array declarations or definitions? (A) int[] []x[]; (B) int x[5]; (C) int *x; (D) None of above

A: int[] []x[];

Ques 95 : Which of these is a legal definition of a method named m assuming it throws IOException, and returns void. Also assume that the method does not take any arguments. Select the one correct answer. (A) void m() throws IOException{} (B) void m() throw IOException{} (C) void m(void) throws IOException{} (D) void m() {} throws IOException

A: void m() throws IOException{}

Ques 41 : Which operator is used to perform bitwise inversion in Java. Select the one correct answer. (A) ~ (B) ! (C) & (D) ^

A: ~

Ques 22 : What is returned when the method substring(2, 4) is invoked on the string "example"? Include the answer in quotes as the result is of type String. (A) "xa" (B) "am" (C) "xm" (D) "xamp"

B: "am"

Ques 81 : What is the range of values that can be specified for an int. Select the one correct answer. (A) The range of values is compiler dependent. (B) -231 to 231 - 1 (C) 231-1 to 231 (D) -215 to 215 - 1

B: -231 to 231 - 1

Ques 66 : What all gets printed when the following gets compiled and run. Select the two correct answers. public class test { public static void main(String args[]) { String s1 = "abc"; String s2 = "abc"; if(s1 == s2) System.out.println(1); else System.out.println(2); if(s1.equals(s2)) System.out.println(3); else System.out.println(4); } } (A) 1 2 (B) 1 3 (C) 1 4 (D) 2 4

B: 1 3

Ques 53 : What is the value of "number" after the following code fragment execution? int number = 0; int number2 = 12 while (number < number2) { number = number + 1; } (A) 5 (B) 12 (C) 13 (D) 21

B: 12

Ques 46 : How many bytes are used to represent the primitive data type int in Java. Select the one correct answer. (A) 2 (B) 4 (C) 8 (D) 1

B: 4

Ques 59 : The width in bits of double primitive type in Java is --. Select the one correct answer. (A) The width of double is platform dependent (B) 64 (C) 128 (D) 8

B: 64

Ques 29 : Which of the following is considered as a blue print that defines the variables and methods common to all of its objects of a specific kind? (A) Object (B) Class (C) Method (D) Real data types

B: Class

Ques 35 : Is this True or False. In Java an abstract class cannot be sub-classed. (A) True (B) False

B: False

Ques 42 : Is this True or False. In Java a final class must be sub-classed before it can be used.

B: False

Ques 48 : Is this true or false. Map interface is derived from the Collection interface. (A) True (B) False

B: False

Ques 26 : What is the name of collection interface used to maintain non-unique elements in order? (A) Set (B) List (C) Map (D) SortedSet

B: List

Ques 52 : Name the access modifier which when used with a method, makes it available to all the classes in the same package and to all the subclasses of the class. (A) public (B) protected (C) private (D) default

B: Protected

Ques 32 : What is the name of collection interface used to maintain unique elements. (A) List (B) Set (C) Map (D) All of above

B: Set

Ques 37 : What are the two parts of a value of type double? (A) Length, Denominator (B) Significant Digits, Exponent (C) Mode, Numerator (D) Length, Numerator

B: Significant Digits, Exponents

Ques 28 : Which of the following is correct? Select the correct answers among the following: a. The native keyword indicates that the method is implemented in another language like C/C++. b. The only statements that can appear before an import statement in a Java file are comments. c. The method definitions inside interfaces are public and abstract. They cannot be private or protected. d. A class constructor may have public or protected keyword before them, nothing else. (A) a, b (B) a, c (C) b, c (D) c, d

B: a, c Reason: Please note that b is not correct, since a package statement may appear before an import statement. A class constructor may be declared private also, therefore d is also incorrect.

Ques 74 : Which expression can be used to access the last element of an array. Select the one correct answer. (A) array[array.length] (B) array[array.length - 1] (C) array[array.length() - 1] (D) array[array.length()]

B: array[array.length - 1] Reason: array.length gives the number of elements in the array. As indexes in Java start from 0, d is the correct answer.

Ques 90 : Which all lines are part of the output when the following code is compiled and run. Select the nine correct answers. public class test { public static void main(String args[]) { for(int i = 0; i < 3; i++) { for(int j = 3; j >= 0; j--) { if(i == j) continue; 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 (A) a, b, c, d, e, i, j, k, l (B) b, c, d, e, g, h, i, j, l (C) b, c, e, j, k, l, f, h, i (D) c, d, e, f, g, h, i

B: b, c, d, e, g, h, i, j, l

Ques 20 : Which of the following is a Java keyword. Select the correct answers among the following: a. extern b. synchronized c. volatile d. friend e. friendly f. transient g. this h. then (A) b, c (B) b, c, f, g (C) e, g, h (D) all of above.

B: b, c, f, g

Ques 45 : After the following code fragment, what is the value in fname? String str; int fname; str = "Foolish boy."; fname = str.indexOf("fool"); (A) 0 (B) 2 (C) -1 (D) 4

C: -1 Reason: str.indexOf is a case sensitive function. "fool" and "Fool" are considered different.

Ques 54 : What is the legal range of values for a variable declared as a byte. Select the one correct answer. (A) 0 to 255 (B) 0 to 256 (C) -128 to 127 (D) -127 to 128

C: -128 to 127

Ques 50 : What gets printed when the following program is compiled and run. Select the one correct answer. public class test { public static void main(String args[]) { byte x = 3; x = (byte)~x; System.out.println(x); } } (A) 0 (B) 3 (C) -4 (D) none of these

C: -4

Ques 80 : What all gets printed when the following gets compiled and run. Select the correct answers from the following: public class example { public static void main(String args[]) { int x = 0; if(x > 0) x = 1; switch(x) { case 1: System.out.println(1); case 0: System.out.println(0); case 2: System.out.println(2); break; case 3: System.out.println(3); default: System.out.println(4); break; } } } A. 0 B. 1 C. 2 D. 3 E. 4

C: 0, 2

Ques 89 : What all gets printed when the following code is compiled and run. Select the three correct answers. class test { public static void main(String args[]) { int i[] = {0,1}; try { i[2] = i[0] + i[1]; } catch(ArrayIndexOutOfBoundsException e1) { System.out.println("1"); } catch(Exception e2) { System.out.println("2"); } finally { System.out.println(3); } System.out.println("4"); } } a. 1 b. 2 c. 3 d. 4 (A) 1 2 4 (B) 4 (C) 1 3 4 (D) 1 2 3

C: 1 3 4 Reason: The exception ArrayIndexOutOfBoundsException is generated as the main method tries to access i[2]. Hence 1 gets printed. After this finally block gets excuted, before the program exits.

Ques 25 : What gets printed when the following program is compiled and run? Select the one correct answer. class xyz { public static void main(String args[]) { int i,j,k; for (i = 0; i < 3; i++) { for(j=1; j < 4; j++) { for(k=2; k<5; k++) { if((i == j) && (j==k)) { System.out.println(i); } } } } } } (A) 0 (B) 1 (C) 2 (D) 3

C: 2 Reason: During various iterations of three loops, the only time i, j, and k have the same values are when all of them are set to 2.

Ques 71 : What all gets printed when the following gets compiled and run. Select the two correct answers. public class test { public static void main(String args[]) { String s1 = "abc"; String s2 = new String("abc"); if(s1 == s2) System.out.println(1); else System.out.println(2); if(s1.equals(s2)) System.out.println(3); else System.out.println(4); } } (A) 1 3 (B) 1 4 (C) 2 3 (D) 2 4

C: 2 3

Ques 36 : What is the result of evaluating the expression 14 ^ 23. Select the one correct answer: (A) 23 (B) 24 (C) 25 (D) 26

C: 25

Ques 92 : Consider the code snippet, and determine the answer: if( "Welcome".trim() == "Welcome".trim() ) System.out.println("Equal"); else System.out.println("Not Equal");

C: Cause a compiler error

Ques 14 : The class Hashtable is used to implement which collection interface. Select the one correct answer. (A) List (B) Set (C) Map (D) SortedSet

C: Map Note: The collection interface Map has two implementations: HashMap and Hashtable.

Ques 12 : Which of the following statements is false about objects? (A) An instance of a class is an object (B) Objects can access both static and instance data (C) Objects do not permit encapsulation (D) Object is the super class of all other classes

C: Objects do not permit encapsulation

Ques 62 : Which of the following statements is true? (A) The default char data type is a space(" ") character. (B) The default integer data type is "long" and real data type is "float" (C) The default integer data type is "int" and real data type is "double" (D) The default integer data type is "int" and real data type is "float"

C: The default integer data type is "int" and real data type is "double"

Ques 19 : In the following class definition, which is the first line (if any) that causes a compilation error. Select the one correct answer. public class test { public static void main(String args[]) { char c; int i; c = 'A'; // 1 i = c; // 2 c = i + 1; // 3 c++; // 4 } } (A) The line labeled 1. (B) The line labeled 2. (C) The line labeled 3. (D) All the lines are correct and the program compiles.

C: The line labeled 3 Reason: It is not possible to assign an integer to a character in this case without a cast.

Ques 88 : What is the result of compiling and running this program? Select the one correct answer. public class test { public static void main(String args[]) { int i, j; int k = 0; j = 2; k = j = i = 1; System.out.println(k); } } (A) The program does not compile as k is being read without being initialized. (B) The program does not compile because of the statement k = j = i = 1; (C) The program compiles and runs printing 1. (D) The program compiles and runs printing 2.

C: The program compiles and runs printing 1

Ques 68 : What would be the results of compiling and running the following class. Select the one correct answer. class test { public static void main() { System.out.println("test"); } } (A) The program compiles and runs but does not generate any output. (B) The program compiles and runs generating an output of "test" (C) The program compiles but does not run. (D) The program does not compile as there is no main method defined

C: The program compiles but does not run

Ques 17 : What happens when the following code is compiled and run. Select the one correct answer. for(int i = 1; i < 3; i++) { for(int j = 3; j > i; j--) { assert i!=j {System.out.println(i); } } (A) The class compiles and runs, but does not print anything. (B) The number 1 gets printed with AssertionError (C) The program generates a compilation error. (D) The number 2 gets printed with AssertionError

C: The program generates a compilation error. Reason: The condition in the assert statement must be followed by a semi-colon. [ assert i!=j; {System.out.println(i); ]

Ques 24 : Which of these are Java keywords. Select the correct answers among the following: a. TRUE b. volatile c. transient d. native e. interface f. then g. new (A) b, d, f, g (B) a, b, d, g (C) b, c, d, e, g (D) d, e, f, g

C: b, c, d, e, g

Ques 98 : 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[]) { for(int i = 0; i < 3; i++) { for(int j = 3; j >= 0; j--) { if(i == j) break; 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 (A) a, b, c, f, h, i (B) c, d, g, h, i, k (C) b, c, d, g, h, l (D) d, e, f, g, j, k

C: b, c, d, g, h, l

Ques 76 : Which of the following are legal array declarations. Select the three correct answers. a. int i[5][]; b. int i[][]; c. int []i[]; d. int i[5][5]; e. int[][] a; (A) a, d, e (B) b, c, d (C) b, c, e (D) a, c, e

C: b, c, e

Ques 99 : Which of the following are legal identifier names in Java. Select the two correct answers. a. %abcd b. $abcd c. 1abcd d. package e. _a_long_name (A) a, c (B) b, d (C) b, e (D) a, e

C: b, e

Ques 6 : Which of these are NOT legal identifiers? (A) 1alpha (B) xy+abc (C) both A and B (D) None of the above

C: both A and B

Ques 55 : Given the following declarations, which of the assignments given in the options below would compile. Select the two correct answers. int i = 5; boolean t = true; float f = 2.3F; double d = 2.3; a. t = (boolean) i; b. f = d; c. d = i; d. i = 5; e. f = 2.8; (A) a,b (B) b,c (C) c,d (D) a,d

C: c, d Reason: Java does not allow casts between boolean values and any numberic types. Hence a is incorrect. Assigning double to a float requires an explicit cast. Hence b and e are incorrect

Ques 61 : What all gets printed when the following gets compiled and run. Select the correct answers from the following: public class test { public static void main(String args[]) { int i=1, j=1; try { i++; j--; if(i == j) { i++; } } catch(ArithmeticException e) { System.out.println(0); } catch(ArrayIndexOutOfBoundsException e) { System.out.println(1); } catch(Exception e) { System.out.println(2); } finally { System.out.println(3); } System.out.println(4); } } a. 0 b. 1 c. 2 d. 3 e. 4 (A) a,d,c (B) b,c,a (C) d,e (D) a,b

C: d, e

Ques 93 : A program needs to store the name, salary, and age of employees in years. Which of the following data types should be used to create the Employee class. Select the three correct answers. a. char b. boolean c. Boolean d. String e. int f. double (A) a,d,f (B) a,e,f (C) d,e,f (D) d,a,e

C: d, e, f

Ques 72 : Which of the following statements declare class Sample to belong to the payroll.admindept package? (A) package payroll;package admindept; (B) package payroll.admindept.Sample; (C) package payroll.admindept; (D) import payroll.admindept.*

C: package payroll.admindept;

Ques 57 : Name the access modifier which when used with a method, makes it available to all the classes in the same package and to all the subclasses of the class. (A) public (B) private (C) protected (D) default

C: protected

Ques 7 : Which of the following are legal definitions of the main method that can be used to execute a class? (A) public static int main(String args[]) (B) public void main(String args) (C) public static void main(String args[]) (D) public static void main(string args[])

C: public static void main(String args[])

Ques 2 : What is the meaning of the return data type void? (A) An empty memory space is returned so that the developers can utilize it. (B) void is not supported in Java (C) void returns no data type. (D) null

C: void returns no data type.

Ques 47 : Select the one correct answer. The smallest number that can be represented using short primitive type in Java is... (A) -127 (B) -128 (C) 0 (D) -32768

D: -32768

Ques 11 : What gets printed when the following code is compiled and run with the following command - java test 2 Select the one correct answer: public class test { public static void main(String args[]) { Integer intObj=Integer.valueOf(args[args.length-1]); int i = intObj.intValue(); if (args.length > 1) { System.out.println(i); } if (args.length > 0) { System.out.println(i - 1); } else { System.out.println(i - 2); } } (A) test (B) test -1 (C) 0 (D) 1

D: 1 Reason: Note that the program gets one command line argument - 2. args.length will get set to 1. So the condition if(args.length > 1) will fail, and the second check if(args.length > 0) will return true.

Ques 86 : How can you ensure that the memory allocated by an object is freed. Select the one correct answer. (A) By invoking the free method on the object. (B) By calling system.gc() method. (C) By setting all references to the object to new values (say null). (D) Garbage collection cannot be forced. The programmer cannot force the JVM to free the memory used by an object.

D: Garbage collection cannot be forced. The programmer cannot force the JVM to free the memory used by an object

Ques 79 : Which of the following statements are correct. Select the one correct answer. (A) Each Java file must have exactly one package statement to specify where the class is stored. (B) If a Java file has both import and package statement, the import statement must come before package statement. (C) A Java file has at least one class defined. (D) If a Java file has a package statement, it must be the first statement (except comments).

D: If a Java file has a package statement, it must be the first statement (except comments). Reason: import statement, package statement and class definitions are all optional in a file. Hence a and c are incorrect. If both import and package statements are present in a file, then package statement must appear before the import statement. Hence b is incorrect.

Ques 40 : What is the name of collection interface used to maintain mappings of keys to values. (A) List (B) Set (C) SortedSet (D) Map

D: Map

Ques 23 : A class can have many methods with the same name as long as the number of parameters or type of parameters is different. This OOP concept is known as... (A) Method Invocating (B) Method Overriding (C) Method Labeling (D) Method Overloading

D: Method Overloading

Ques 15 : TreeMap class is used to implement which collection interface. Select the one correct answer. (A) Set (B) SortedSet (C) Tree (D) SortedMap

D: SortedMap

Ques 85 : What happens when the following class is compiled and run. Select one correct answer. public class test { public static void main(String args[]) { int x = 0, y = 1, z; if(x) z = 0; else z = 1; if(y) z = 2; else z = 3; System.out.println(z); } } (A) The program prints 1 (B) The program prints 2 (C) The program prints 3 (D) The program does not compile because of problems in the if statement.

D: The program does not compile because of problems in the if statement Reason: The expression in the if statement must evaluate to a Boolean

Ques 94 : Which all lines are part of the output when the following code is compiled and run. Select the one correct answer. public class test { public static void main(String args[]) { for(int i = 0; i < 3; i++) { for(int j = 3; j <= 0; j--) { if(i == j) continue; System.out.println(i + " " + j); } } } } (A) 1 2 (B) 1 3 (C) 2 0 (D) The program does not print anything.

D: The program does not print anything

Question 49 : What is the result of compiling and running the following class. Select the one correct answer. class Test { public void methodA(int i) { System.out.println(i); } public int methodA(int i) { System.out.println(i+1); return i+1; } public static void main(String args[]) { Test X = new Test(); X.methodA(5); } } (A) The program compiles and runs printing 5. (B) The program compiles and runs printing 6. (C) The program gives a runtime exception because it does not find the method Test.methodA(int) (D) The program gives a compilation error because methodA is defined twice in class Test.

D: The program gives a compilation error because methodA is defined twice in class Test

Ques 84 : What happens when the following program is compiled and then the command "java check it out" is executed. Select the one correct answer. class check { public static void main(String args[]) { System.out.println(args[args.length-2]); } } (A) The program compiles but generates ArrayIndexOutOfBoundsException exception (B) The program prints java (C) The program prints check (D) The program prints it

D: The program prints it Reason: The args array consists of two elements "it" and "out". args.length is set to two.

Ques 27: Which of the following statement is true about the assert statement. Select the one correct answer. (A) If a Java class contains assert statements, then it must be compiled with -1.4 option. (B) When a program having assertions is run, -assertion option must be specified, otherwise the assertions get ignored. (C) A possible syntax of assert statement is assert logical_expression If logical_expression evaluates to true, the program generates an AssertionError. (D) The program terminates on its first AssertionError.

D: The program terminates on its first AssertionError Reason: The option A is incorrect, as the Java compiler option is -source 1.4 . The option B is incorrect, as the runtime option is -ea or -enableassertions. If the logical expression evaluates to false, then the program generates an AssertionError, hence C is incorrect.

Ques 100 : What gets printed on the standard output when the class below is compiled and executed by entering "java test lets see what happens". Select the one correct answer. public class test { public static void main(String args[]) { System.out.println(args[0] + " " + args[args.length-1]); } } (A) The program will print - java what (B) The program will print - java test (C) The program will throw an ArrayIndexOutOfBounds exception. (D) The program will print - lets happens

D: The program will print - lets happens

Ques 39 : What gets printed when the following program is compiled and run? Select the one correct answer: class test { static boolean check; public static void main(String args[]) { int i; if (check == true) { i=1; } else { i=2; } if(i=2) i=i+2; else i = i + 4; System.out.println(i); } } (A) 3 (B) 4 (C) 5 (D) The program does not compile because of the statement if(i=2)

D: The statement does not compile because of the statement if (i=2) Reason: The statement "i = 2" evaluates to 2. The expression within the if block must evaluate to a Boolean

Ques 9 : Which of the following are keywords in Java? (A) implement (B) friend (C) NULL (D) synchronized

D: synchronized


Related study sets

CA LIFE STATE PRACTICE EXAM PT 2(FROM EXAM FX ONLINE TEST)

View Set

Unit 8 Practice quiz -------- Metabolism

View Set

Absolutism and Constitutionalism

View Set

CK12 Biology Chapter 3 combined vocabulary

View Set