Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 23

What is the output of the following code? (Choose one)


Options are :

  • Spring String false
  • Autumn Autumn false
  • Compilation error (Correct)
  • String Autumn false
  • Runtime exception

Answer :Compilation error

What is the output of the following code? (Choose one)


Options are :

  • 102
  • 100
  • No output is produced.
  • Code fails to compile. (Correct)
  • 101

Answer :Code fails to compile.

Given the following code, which option, if used to replace /* INSERT CODE HERE */, will cause the code to print 110? (Choose one)


Options are :

  • None of the above (Correct)
  • return super.pages + interviews*5;
  • return super.pages + this.interviews*5;
  • return this.pages + this.interviews*5;
  • return pages + this.interviews*5;

Answer :None of the above

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 35

Choose the options that meets the following specification: Create a well-encapsulated class Pencil with one instance variable model. The value of model should be accessible and modifiable outside Pencil. (Choose one)


Options are :

  • class Pencil { public String model; }
  • class Pencil { private String model; public String getModel() { return model; } public void setModel(String val) { model = val; } } (Correct)
  • class Pencil { public String model; public String getModel() { return model; } public void setModel(String val) { model = val; } }
  • class Pencil { public String model; private String getModel() { return model; } private void setModel(String val) { model = val; } }

Answer :class Pencil { private String model; public String getModel() { return model; } public void setModel(String val) { model = val; } }

Examine the following code and select the correct statement (choose one).


Options are :

  • A. The code will print LionX.
  • B. The code will print Lion. (Correct)
  • D. The code will compile only when line 4 is changed to the following: StringBuilder ejg = null;
  • C. The code will print Lion if line 5 is changed to the following: ejg = sb1.append("X").substring(sb1.indexOf('L'), sb1.indexOf('X'));

Answer :B. The code will print Lion.

Given that the file Test.java, which defines the following code, fails to compile, select the reasons for the compilation failure (choose all that apply).


Options are :

  • The code that creates an object of the class Employee in the class Test did not pass a String value to the constructor of the class Employee.
  • The default constructor can call only a no-argument constructor of a base class. (Correct)
  • The class Employee fails to compile. (Correct)
  • The class Person fails to compile.

Answer :The default constructor can call only a no-argument constructor of a base class. The class Employee fails to compile.

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 48

Given the following code, which code can be used to create and initialize an


Options are :

  • C. ColorPencil var3 = new ColorPencil("RED"); (Correct)
  • A. ColorPencil var1 = new ColorPencil();
  • D. Pencil var4 = new ColorPencil("BLUE"); (Correct)
  • B. ColorPencil var2 = new ColorPencil(RED);

Answer :C. ColorPencil var3 = new ColorPencil("RED"); D. Pencil var4 = new ColorPencil("BLUE");

Given the following code, which option, if used to replace /*INSERT CODE HERE*/, will make the code print 1 ? (Choose one)



Options are :

  • A. IndexPositionException e
  • D. ArrayOutOfBoundsException e
  • C. ArrayIndexOutOfBoundsException e (Correct)
  • B. NullPointerException e

Answer :C. ArrayIndexOutOfBoundsException e

Which of the following will compile successfully? (Choose all that apply)


Options are :

  • D. int[] eArr4 = new int[10] {};
  • A. int eArr1[] = {10, 23, 10, 2}; (Correct)
  • int eArr5[] = new int[2] {10, 20};
  • B. int[] eArr2 = new int[10]; (Correct)
  • C. int[] eArr3 = new int[] {}; (Correct)

Answer :A. int eArr1[] = {10, 23, 10, 2}; B. int[] eArr2 = new int[10]; C. int[] eArr3 = new int[] {};

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 40

How many Fish did the Whale (defined as follows) manage to eat? Examine the following code and select the correct statements (choose all that apply).


Options are :

  • B. The code doesn't print a value. (Correct)
  • D. Changing ++Fish.count to Fish.count++ will give the same results. (Correct)
  • C. The code prints 0.
  • A. The code doesn't compile.

Answer :B. The code doesn't print a value. D. Changing ++Fish.count to Fish.count++ will give the same results.

What is the output of the following code? (Choose one)


Options are :

  • 61
  • 60
  • The code fails to compile.
  • 59
  • No output (Correct)

Answer :No output

Assume that Oracle has asked you to create a method that returns the concatenated value of two String objects. Which of the following methods can accomplish this job? (Choose all that apply)


Options are :

  • B. private String add(String s1, String s2) { return s1.concat(s2); } (Correct)
  • C. protected String add(String value1, String value2) { return value2.append(value2); }
  • A. public String add(String 1, String 2) { return str1 + str2; }
  • D. String subtract(String first, String second) { return first.concat(second.substring(0)); } (Correct)

Answer :B. private String add(String s1, String s2) { return s1.concat(s2); } D. String subtract(String first, String second) { return first.concat(second.substring(0)); }

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 11

Given the following,

which options, when inserted at //INSERT CODE HERE, will output 14? (Choose all that apply)


Options are :

  • A. for (char c1 : arrC1) { for (char c2 : arrC2) { if (c2 == 'a') break; ++ctr; } } (Correct)
  • D. for (char c1 : arrC1) { for (char c2 : arrC2) { if (c2 == 'a') continue; ++ctr; } }
  • B. for (char c1 : arrC1) for (char c2 : arrC2) { if (c2 == 'a') break; ++ctr; } (Correct)
  • C. for (char c1 : arrC1) for (char c2 : arrC2) if (c2 == 'a') break; ++ctr;

Answer :A. for (char c1 : arrC1) { for (char c2 : arrC2) { if (c2 == 'a') break; ++ctr; } } B. for (char c1 : arrC1) for (char c2 : arrC2) { if (c2 == 'a') break; ++ctr; }

Which of the following options are valid for defining multidimensional arrays? (Choose all that apply)


Options are :

  • C. String ejg3[][] = new String[2][2]; (Correct)
  • F. String ejg6[][] = new String[][]{"A", "B"};
  • D. String ejg4[][] = new String[][]{{null},new String[]{"a","b","c"},{new String()}}; (Correct)
  • E. String ejg5[][] = new String[][2];
  • B. String ejg2[][] = new String[][] { {}, {} }; (Correct)
  • A. String ejg1[][] = new String[1][2]; (Correct)
  • G. String ejg7[][] = new String[]{{"A"}, {"B"}};

Answer :C. String ejg3[][] = new String[2][2]; D. String ejg4[][] = new String[][]{{null},new String[]{"a","b","c"},{new String()}}; B. String ejg2[][] = new String[][] { {}, {} }; A. String ejg1[][] = new String[1][2];

What is the output of the following code? (Choose one)


Options are :

  • The class won't compile. (Correct)
  • The class will print true if the if condition is changed to boolean == true.
  • Runtime exception
  • The class will print false.
  • The class will print true.
  • The class will print false if the if condition is changed to boolean != true.

Answer :The class won't compile.

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 2

What is the output of the following code? (Select 1 option.)


Options are :

  • 8 (Correct)
  • 5
  • 9
  • 6

Answer :8

Which of the following options defines the correct structure of a Java class that compiles successfully? (Choose one)


Options are :

  • B. import com.ejava.guru.*; import com.ejava.oracle.*; package com.ejava; class MyClass { String name = "e" + "Ja /*va*/ v"; }
  • D. class MyClass { int abc; String course = //this is a comment "eJava"; } (Correct)
  • E. None of the above
  • C. class MyClass { import com.ejava.guru.*; }
  • A. package com.ejava.guru; package com.ejava.oracle; class MyClass { int age = /* 25 */ 74; }

Answer :D. class MyClass { int abc; String course = //this is a comment "eJava"; }

What is the output of the following code? (Choose one)


Options are :

  • 11 13 15 17 19
  • Compilation error
  • 11 14 17 20
  • 40
  • 20 (Correct)

Answer :20

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 35

What is the output of the following code? (Select 1 option.)


Options are :

  • 3456789
  • 234567890
  • Compilation error
  • Runtime exception (Correct)
  • 234456789
  • 34567890

Answer :Runtime exception

What is the output of the following code? (Select 1 option.)


Options are :

  • None of the above
  • OCA Java (Correct)
  • Java Java
  • OCA OCA

Answer :OCA Java

What is the output of the following code? (Choose one)


Options are :

  • Compilation error
  • blue (Correct)
  • red
  • No output

Answer :blue

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 28

Which of the following statements are correct? (Choose all that apply)


Options are :

  • StringBuilder sb1 = new StringBuilder(5*10) will create a StringBuilder object with a value of 50.
  • StringBuilder sb1 = new StringBuilder() will create a StringBuilder object with no characters but with an initial capacity to store 16 characters. (Correct)
  • The insert method can be used to insert a character, number, or String at the start or end or a specified position of a StringBuilder. (Correct)
  • Unlike the class String, the concat method in StringBuilder modifies the value of a StringBuilder object.

Answer :StringBuilder sb1 = new StringBuilder() will create a StringBuilder object with no characters but with an initial capacity to store 16 characters. The insert method can be used to insert a character, number, or String at the start or end or a specified position of a StringBuilder.

What is the output of the following code? (Select 1 option.)


Options are :

  • Call-Phone null
  • Call-Phone Call-SmartPhone (Correct)
  • Call-Phone Call-Phone
  • null Call-SmartPhone

Answer :Call-Phone Call-SmartPhone

Select the most appropriate definition of the variable name and the line number on which it should be declared so that the following code compiles successfully (choose 1 option).


Options are :

  • Define static String name; on line 1. (Correct)
  • Define String name; on line 1.
  • Define String name; on line 3.
  • Define String name; on line 2.

Answer :Define static String name; on line 1.

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 43

Given the following definitions of the class ChemistryBook, select the statements that are correct individually (choose all that apply):


Options are :

  • B. Methods marked with //METHOD2 and //METHOD3 are correctly overloaded methods. (Correct)
  • C. Methods marked with //METHOD1 and //METHOD3 are correctly overloaded methods. (Correct)
  • A. Methods marked with //METHOD1 and //METHOD2 are correctly overloaded methods.
  • D. All the methods—methods marked with //METHOD1, //METHOD2, and //METHOD3 are correctly overloaded methods.

Answer :B. Methods marked with //METHOD2 and //METHOD3 are correctly overloaded methods. C. Methods marked with //METHOD1 and //METHOD3 are correctly overloaded methods.

What is the output of the following code? (Choose one)


Options are :

  • null:true
  • Compilation error (Correct)
  • in-built:true
  • in-built:false
  • null:false

Answer :Compilation error

Given the following code, which of the following statements are true? (Choose all that apply)


Options are :

  • A. The code will print caught.
  • B. The code won't print caught.
  • E. The code would print caught if question() throws the exception NullPointerException.
  • D. The code would print caught if StackOverflowError were a checked exception. (Correct)
  • C. The code would print caught if StackOverflowError were a runtime exception. (Correct)

Answer :D. The code would print caught if StackOverflowError were a checked exception. C. The code would print caught if StackOverflowError were a runtime exception.

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 24

What is the output of the following code? (Choose one)


Options are :

  • false:true
  • true:false
  • Compilation error—there is no equals method in the class Book.
  • true:true
  • Runtime exception
  • false:false (Correct)

Answer :false:false

Given the following code, which option, if used to replace //INSERT CODE HERE, will correctly calculate the sum of all the even numbers in the array num and store it in the variable sum? (Choose one)


Options are :

  • A. if (number % 2 == 0) continue;
  • D. if (number % 2 != 0) break;
  • C. if (number % 2 != 0) continue; (Correct)
  • B. if (number % 2 == 0) break;

Answer :C. if (number % 2 != 0) continue;

Given the following class definition,

class Student { int marks = 10; }

what is the output of the following code? (Choose one)



Options are :

  • 100 10 98
  • 10
  • 10 98 (Correct)
  • 100

Answer :10 98

Oracle Java SE 8 Certification - OCAJP 1Z0-808 Practice Tests Set 36

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions