JavaBeat

  • Home
  • 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)
  • Privacy

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?

[code lang=”java”]
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]);
}
}
[/code]

Choose the one below:

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

4 . What will be the output?

[code lang=”java”]
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]);
}
}
[/code]

Choose the one below:

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

5 . What will be the output?

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

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?

[code lang=”java”]
char[] c = new char[100];
[/code]

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?

[code lang=”java”]
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]);
}
}
[/code]

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.

Filed Under: Certifications Tagged With: 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.

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.

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved