TEST 4 4 Feb,2022 boomtecho2@gmail.comLeave a comment 1. In java Array are : objects object references primitive data type none of the above 2. Which one of the following is a valid statement? char[] c = new char(); char[] c = new char[5]; char[] c = new char(4); char[] c = new char[]; 3. What is the result of compiling and running the following code? public class Test{ public static void main(String[] args){ int[] a = new int[0]; System.out.print(a.length); } } 0 Compilation error, arrays cannot be initialized to zero size. Compilation error, it is a.length() not a.length None of the above 4. Which of these is an incorrect array declaration? int arr[] = new int[5] int [] arr = new int[5] int arr[] = new int[5] int arr[] = int [5] new 5. What will be the output of following code ? int arr[] = new int [5]; System.out.print(arr); 0 value stored in arr[0] 00000 Class name@ hashcode in hexadecimal form 6. Which of these is an incorrect Statement? It is necessary to use new operator to initialize an array Array can be initialized using comma separated expressions surrounded by curly braces Array can be initialized when they are declared None of the mentioned 7. How many of the following are legal declarations? []double lion; double[] tiger; double bear[]; one two three none 8. How do you determine the number of elements in an array? int buses[] = new int[5]; buses.length buses.length() buses.size buses.size() 9. Which of the following create an empty two-dimensional array with dimensions 2×2? int[][] blue = new int[2, 2]; int[][] blue = new int[2], [2]; int[][] blue = new int[2][2]; int[][] blue = new int[2 x 2]; 10. What does this code output ? String[] nums = new String[] { "1", "9", "10" }; Arrays.sort(nums); System.out.println(Arrays.toString(nums)); [1,9,10] [1,10,9] [10,1,9] none of above 11. How many of the following are legal declarations? 1.float[] lion = new float[]; 2.float[] tiger = new float[1]; 3.float[] bear = new[] float; 4.float[] cat = new[1] float; one two three four 12. size of an array we can declared in long data type? True false none 13. size of an array we can declared in long data type? True false none 14. What does the following output? String[] os = new String[] { "Mac", "Linux", "Windows" }; Arrays.sort(os); System.out.println(Arrays.binarySearch(os, "Mac")); 0 1 2 the output is not defined 15. What is the output of the following code fragments? int [ ] fun = new int [5]; fun[0] = 1; fun[1] = 2; fun[2] = 3; fun[3] = 4; fun[4] = 5; int j = 3; System.out.println(fun[ j-1]) ; 1 2 3 4 16. What is the output of the following code fragment? int [ ] odd = {1, 3, 5, 7, 9, 11 }; System.out.println( odd[0] + ” ” + odd[3] ) ; 1,5 6 1,7 8 17. Which of these is necessary to specify at time of array initialization? Row Row and Column column none of above 18. What will be the output following code class array_output { public static void main(String args[]) { int array_variable [] = new int[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = i; System.out.print(array_variable[i] + " "); i++; } } } 0 1 2 3 4 5 6 7 8 9 1 3 5 7 9 0 2 4 6 8 1 2 3 4 5 6 7 8 9 10 19. Determine the output public class array { public static void main(String args[]) { int []x={ 1,2,3,4}; int []y=x; x=new int[2]; for (int i=0; i<x.lenght;i++) System.out.println(y[i] + “”); } } 1234 0000 1 2 0 0 20. When you pass an array to a method , the method receives : A copy of the Array A copy of the first element The reference of the array The length of the Array 21. What does the following method do? public static void numbers (int [ ] num) { for(int x = 1; x < num.length; x++) num[x] = num[0]; } It copies what is in cell 0 into all other cells. It changes every element to the value of x. It copies 0 into every element. It puts the array into numerical ascending order. 22. 19. What is the length of this array? double[ ] stuff = {1.5, 2.5, 3.5, 4.5, 5.5, 6.5}; 1 5 6 7 23. What is the output of the following code fragmented ? int [ ] array = { 2, 4, 6, 8, 1, 3, 5, 7}; int george = 0; for (int i = 0; i < array.length; i++) george += array[i]; System.out.print(george); 2 4 6 8 1 3 5 7 2 4 6 8 7 36 24. Which of the following is advantage of java array? code optimization Random Access Size No Limit both a and b 25. What will be the output class Main { public static void main(String args[]) { int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9}; int n = 6; n = arr[arr[n] / 2]; System.out.print(n); } } 3 0 6 1 26. Array is a collection of ________. different type of elements collection of same data type heterogeneous data both A and C 27. Array can allocate __________. Static Memory Dynamic Memory Automatic None of the Above 28. Which of these is an incorrect Statement? It is necessary to use new operator to initialize an array. Array can be initialized using comma separated expressions surrounded by curly braces. Array can be initialized when they are declared. none of above 29. 16. What is the output from the following code fragment? String [ ] name = { "Joe", "Sue", "Tom", "Jill", "Patty"}; for (int i = 0; i < name.length; i = i + 2) System.out.print(name[i] + " "); Joe Sue Tom Jill Patty Patty Jill Tom Sue Joe Joe Tom Patty Sue Jill 30. What is the output of the program after compile and Run : class Mango { public static void main() { System,out,println(“Mango”); } } Program will compile , but not Run Program output “Mango” Error no Main method define Above all are wrong 31. When program will be compiled then what will be the part of output,select any one from the followings: public class less { public static void main(String p[]) { for(int m=0;m<3;m++) { for(int n=3;n>=0;n–) { if(m==n) break; System.out.println(m+” “+n); } } } } 00 13 2 -2 0 -3 32. When program will be compiled then what will the part of output ,select any one from the followings: public class count { public static void main(String E[]) { for(int m=0;m<3;m++) { for(int n=3;n>0;n–) { if(m==n) continue; System.out.println(m+” “+n); } } } } 0 0 1 1 2 2 0 3 33. What will print on screen when following program compiled? public class myprint { public static void main(String K[]) { int m=0; boolean b2=true; boolean b3=false; int b4=(b2&&((m++)==0)); b4=(b3&&((m++)==0)); System.out.println(m); } } compile time error 0 1 2 3 34. What is the output of the following program ? class OK { public static void main(String B[]) { int a,b,c,d=0; c=d++; b=++c; a=b++; System.out.println(a); } } 3 2 1 0 35. When following will be compiled, then at which line error will be notice : public class castPrint { public static void main(String a[]) { char C; int K; C=’A’; K=C; C=K+10; ++C; } } C=’A’; K=’C’; C=K+10; ++C; Loading …