• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

OCPJP 6 Mock Exam – 20

January 23, 2014 //  by Krishna Srinivasan//  Leave a Comment

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.

Category: CertificationsTag: OCPJP, OCPJP 6

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.

Previous Post: « How To Convert String To Byte In Java?
Next Post: OCPJP 6 Mock Exam – 21 »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

EJB 3.0 Timer Services

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact