JavaCore Test 6 What all gets printed when the following gets compiled and run. 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, b d, e b, c, a a, d, c Which of the following statements is true? The default integer data type is "int" and real data type is "float" The default integer data type is "int" and real data type is "double" The default integer data type is "long" and real data type is "float" The default char data type is a space( " " ) character. Which of the following statements are correct. 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. d, e, a, c a, b, d, f b, d, e, f c, d, b, a What is the result of compiling and running the following program. 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; } } 5,6 1,6 5,2 1,2 What gets displayed on the screen when the following program is compiled and run. public class test { public static void main(String args[]) { int x; x = -3 >> 1; x = x >>> 2; x = x << 1; System.out.println(x); } } 2147483646 5 23 7 What all gets printed when the following gets compiled and run. 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); } } 2 4 1 4 1 3 1 2 How many numeric data types are supported in Java? 8 2 4 6 What would be the results of compiling and running the following class. class test { public static void main() { System.out.println("test"); } } The program does not compile as there is no main method defined The program compiles but does not run. The program compiles and runs generating an output of "test" The program compiles and runs but does not generate any output. Which of the following statements are true. If a method tries to access an array element beyond its range, a compile warning is generated. Array elements are indexed from 1 to size of array. Arrays in Java are essentially objects. It is not possible to assign one array to another. Individual elements of array can however be assigned Which of the following are correct. For positive numbers, results of operators >> and >>> are same. >>> is the signed right shift operator. >> is the zero fill right shift operator. Java provides two operators to do left shift - << and <<<. What all gets printed when the following gets compiled and run. 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); } } 1 3 2 4 1 4 2 3 Which of the following statements declare class Sample to belong to the payroll.admindept package? import payroll.admindept.* package payroll.admindept; package payroll.admindept.Sample; package payroll;package admindept; Which of these are valid declarations for the main method? public static int main(String args[]); static public void main(String); public static void main(String args[]); public void main(); Which expression can be used to access the last element of an array. array[array.length()] array[array.length() - 1] array[array.length - 1] array[array.length] What is the result of compiling and running the following program. public class test { public static void main(String args[]) { int i = -1; i = i >> 1; System.out.println(i); } } 1 -1 128 255 Which of the following are legal array declarations. a. int i[5][]; b. int i[][]; c. int []i[]; d. int i[5][5]; e. int[][] a; a, c, e b, c, d b, c, e a, d, e The class java.lang.Exception is ? extends Throwable serializable implements Throwable protected Which of the following are valid declarations for the main method. 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, b, e a, d, c b, d, e a, b, c Which of the following statements are correct. If a Java file has a package statement, it must be the first statement (except comments). A Java file has at least one class defined. If a Java file has both import and package statement, the import statement must come before package statement. Each Java file must have exactly one package statement to specify where the class is stored. What all gets printed when the following gets compiled and run. 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 1 0, 2 3, 4 1, 0, 2 Schreibe einen Kommentar Antworten abbrechenDu musst angemeldet sein, um einen Kommentar abzugeben.