OCPJP 6 Mock Exam – 20

1 . Which of the following are valid array construction?

  1. int a[] = new int[];
  2. int a[] = new int[10];
  3. int a[10] = new int[];
  4. int a[] = new a[10];

2 . Which of the following are valid array initialization?

  1. new int[] = {1,2,3,4};
  2. new int[10] = {1,2,3,4};
  3. new int[] = 1,2,3,4;
  4. new int[] = [1,2,3,4];

3 . What will be the output?

	public class Test3{
    public static void main(String args[]){
         int arr[] = new int[10];
         int i = 5;
         arr[i++] = ++i+i++;
         System.out.print(arr[5]+":"+arr[6]);
     }
}

Choose the one below:

  1. 14:0
  2. 0:14
  3. 0:0
  4. Compiler Error

4 . What will be the output?

	public class Test4{
     public static void main(String args[]){
          int arr[] = new int[10];
          int i = 5;
          arr[i++] = i+++i++;
          System.out.print(arr[5]+":"+arr[6]);
     }
}

Choose the one below:

  1. 13:0
  2. 14:0
  3. 0:14
  4. 0:13

5 . What will be the output?

public class Test5{
    static Boolean bl[] = new Boolean[5];
    public static void main(String args[]){
         System.out.println(bl[0]);
    }
}

Choose the one below:

  1. Null
  2. False
  3. True
  4. Compiler Error

6 . Which of the following are valid array declarations?

  1. String[][] a1 = String[20][20];
  2. String[][] a2 = new String[20,20];
  3. String[][] a3 = new String[20][20];
  4. String a4[][] = new String[20][20];
  5. String[] a5[] = new String[20][20];

7 . Which of the following code correctly creates an array of four initialized string objects?

  1. String players[] = new String[4];
  2. String players[] = {“”,””,””,””};
  3. String players[];
  4. players = new String[4];
  5. None of the above

8 . What will be the output?

char[] c = new char[100];

what is the value of c[50]?

Choose the one below:

  1. 50
  2. 49
  3. ‘\u0000′
  4. ‘\u0020′

9 . which of the following are valid arrays?

  1. new float[10]={1,2};
  2. new float[]={1,2};
  3. new float={1,2};
  4. None of the above

10 . What will be the output?

	public class Test10{
    public void method(int arr[]){
        arr[0] = 10;
    }
    public static void main(String[] args){
        int[] small = {1,2,3};
        Test10 t= new Test10();
        t.method(small);
        System.out.println(small[0]);
    }
}

Choose the one below:

  1. 0
  2. 1
  3. 0
  4. None of the above

Answers

1 : 2 is correct. int a[] = new int[10];

2 : 1 is correct. new int[] = {1,2,3,4};

3 : 1 is correct. 14:0

4 : 1 is correct. 13:0

5 : 1 is correct. Null.

6 : 3,4 & 5 is correct.
3 . String[][] a3 = new String[20][20];
4 . String a4[][] = new String[20][20];
5 . String[] a5[] = new String[20][20];

7 : 2 is correct. String players[] = {“”,””,””,””};

8 : 3 is correct. ‘\u0000′

9 : 2 is correct. new float[]={1,2};

10 : 10.

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*