Java Quiz 5 : Promotions & Casting, Arrays

    Welcome to your Java Quiz 5 : Promotions & Casting, Arrays

    1. What will be the output of the following Java code?
    1.  class char_increment 
    2.  {
    3.  public static void main(String args[]) 
    4.  {
    5.  char c1 = 'D';
    6.  char c2 = 84;
    7.  c2++;
    8.  c1++;
    9.  System.out.println(c1 + " " + c2);
    10.  } 
    11.  }
    2. What will be the output of the following Java code?
    1.  class conversion 
    2.  {
    3.  public static void main(String args[]) 
    4.  {
    5.  double a = 295.04;
    6.  int b = 300;
    7.  byte c = (byte) a;
    8.  byte d = (byte) b;
    9.  System.out.println(c + " " + d);
    10.  } 
    11.  }
    3. What will be the output of the following Java code?

     What will be the output of the following Java code?

    1.  class A 
    2.  {
    3.  final public int calculate(int a, int b) { return 1; } 
    4.  } 
    5.  class B extends A 
    6.  { 
    7.  public int calculate(int a, int b) { return 2; } 
    8.  } 
    9.  public class output 
    10.  {
    11.  public static void main(String args[]) 
    12.  { 
    13.  B object = new B(); 
    14.  System.out.print("b is " + b.calculate(0, 1)); 
    15.  } 
    16.  }
    4. What will be the output of the following Java program, if we run as “java main_arguments 1 2 3”?
    1.  class main_arguments 
    2.  {
    3.  public static void main(String [] args) 
    4.  {
    5.  String [][] argument = new String[2][2];
    6.  int x;
    7.  argument[0] = args;
    8.  x = argument[0].length;
    9.  for (int y = 0; y < x; y++) 
    10.  System.out.print(" " + argument[0][y]); 
    11.  }
    12.  }
    5. What will be the output of the following Java program?
    1.  class c 
    2.  { 
    3.  public void main( String[] args ) 
    4.  { 
    5.  System.out.println( "Hello" + args[0] ); 
    6.  } 
    7.  }
    6. Which of these operators is used to allocate memory to array variable in Java?
    7. Which of these is an incorrect array declaration?
    8. What will be the output of the following Java code?
     int arr[] = new int [5]; System.out.print(arr);
    9. Which of these is an incorrect Statement?
    10. Which of these is necessary to specify at time of array initialization?
    11. What will be the output of the following Java code?
    1.  class array_output 
    2.  {
    3.  public static void main(String args[]) 
    4.  {
    5.  int array_variable [] = new int[10];
    6.  for (int i = 0; i < 10; ++i) 
    7.  {
    8.  array_variable[i] = i;
    9.  System.out.print(array_variable[i] + " ");
    10.  i++;
    11.  }
    12.  } 
    13.  }
    12. What will be the output of the following Java code?
    1.  class multidimention_array 
    2.  {
    3.  public static void main(String args[])
    4.  {
    5.  int arr[][] = new int[3][];
    6.  arr[0] = new int[1];
    7.  arr[1] = new int[2];
    8.  arr[2] = new int[3]; 
    9.  int sum = 0;
    10.  for (int i = 0; i < 3; ++i) 
    11.  for (int j = 0; j < i + 1; ++j)
    12.  arr[i][j] = j + 1;
    13.  for (int i = 0; i < 3; ++i) 
    14.  for (int j = 0; j < i + 1; ++j)
    15.  sum + = arr[i][j];
    16.  System.out.print(sum); 
    17.  } 
    18.  }
    13. What will be the output of the following Java code?
    1.  class evaluate 
    2.  {
    3.  public static void main(String args[]) 
    4.  {
    5.  int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};
    6.  int n = 6;
    7.  n = arr[arr[n] / 2];
    8.  System.out.println(arr[n] / 2);
    9.  } 
    10.  }
    14. What will be the output of the following Java code?
    1.  class array_output 
    2.  {
    3.  public static void main(String args[]) 
    4.  {
    5.  char array_variable [] = new char[10];
    6.  for (int i = 0; i < 10; ++i) 
    7.  {
    8.  array_variable[i] = 'i';
    9.  System.out.print(array_variable[i] + "");
    10.  }
    11.  } 
    12.  }
    15. What will be the output of the following Java code?
    1.  class array_output 
    2.  {
    3.  public static void main(String args[]) 
    4.  {
    5.  int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8, 9}};
    6.  int sum = 0;
    7.  for (int i = 0; i < 3; ++i)
    8.  for (int j = 0; j < 3 ; ++j)
    9.  sum = sum + array_variable[i][j];
    10.  System.out.print(sum / 5);
    11.  } 
    12.  }