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

Consider below code:

What will be the result of compiling and executing Test class?


Options are :

  • false false
  • false true (Correct)
  • true false
  • true true

Answer :false true

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

What will be the result of compiling and executing Test class?


Options are :

  • MANGO ANY FRUIT WILL DO
  • MANGO
  • ANY FRUIT WILL DO (Correct)
  • MANGO BANANA
  • MANGO BANANA ANY FRUIT WILL DO

Answer :ANY FRUIT WILL DO

Which of the following correctly defines class Printer?


Options are :

  • package com.cher.certification; package com.cher.ocp; public class Printer { }
  • package com.cher.certification; package com.cher.ocp; import java.io.* public class Printer { }
  • package com.cher.certification; import java.util.*; public class Printer { } (Correct)
  • public class Printer { package com.cher.certification; }

Answer :package com.cher.certification; import java.util.*; public class Printer { }

What will be the result of compiling and executing Test class?


Options are :

  • true:false
  • null:true (Correct)
  • NullPointerException is thrown at runtime
  • true:true
  • null:null

Answer :null:true

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

Consider below code: 

What will be the result of compiling and executing Test class?


Options are :

  • [Array, List]
  • [List, Array] (Correct)
  • [List]
  • [Array]
  • An exception is thrown at runtime

Answer :[List, Array]

How can you force JVM to run Garbage Collector?


Options are :

  • By setting the reference variable to null.
  • By calling: System.gc();
  • JVM cannot be forced to run Garbage Collector. (Correct)
  • By calling: Runtime.getRuntime().gc();

Answer :JVM cannot be forced to run Garbage Collector.

For the class Test, which options, if used to replace /*INSERT*/, will print TEN on to the console? Select 4 options.


Options are :

  • long var = 10;
  • Integer var = 10; (Correct)
  • Short var = 10; (Correct)
  • byte var = 10; (Correct)
  • double var = 10;
  • char var = 10; (Correct)

Answer :Integer var = 10; Short var = 10; byte var = 10; char var = 10;

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

What is the output if below program is run with the command line:

java Test



Options are :

  • NullPointerException
  • ArrayIndexOutOfBoundsException
  • 0 (Correct)
  • 1

Answer :0

Consider below code: 

What will be the result of compiling and executing Test class?


Options are :

  • Student[James, 27]
  • Student[James, 25] Student[James, 27] Student[James, 25] Student[James, 25]
  • Student[James, 25] Student[James, 27] Student[James, 25]
  • Student[James, 27] Student[James, 25] Student[James, 25] (Correct)

Answer :Student[James, 27] Student[James, 25] Student[James, 25]

Given code of LogHelper.java file:


Which of the following changes, done independently, allows the code to compile and on execution prints LogHelper-help?

Select ALL that apply.


Options are :

  • Add the protected modifier to the log() method of LogHelper class
  • Remove the protected modifier from the operation variable of LogHelper class
  • Add the protected modifier to the log() method of Helper class
  • Add the protected modifier to the help() method of LogHelper class (Correct)
  • Add the public modifier to the log() method of LogHelper class
  • Remove the private modifier from the num variable of LogHelper class
  • Remove the protected modifier from the help() method of Helper class (Correct)
  • Add the public modifier to the help() method of LogHelper class (Correct)

Answer :Add the protected modifier to the help() method of LogHelper class Remove the protected modifier from the help() method of Helper class Add the public modifier to the help() method of LogHelper class

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

Which is not a valid statement based on given code?


Options are :

  • A a = new A();
  • A a = new B();
  • B a = new B();
  • B b = new A(); (Correct)

Answer :B b = new A();

Choose the options that meets the following specification: 

Create a well encapsulated class Clock with one instance variable model. 

The value of model should be accessible and modifiable outside Clock.


Options are :

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

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

What will be the result of compiling and executing Test class?


Options are :

  • 6
  • 753
  • 7
  • 75
  • 7654321
  • 642 (Correct)
  • 64
  • 7531

Answer :642

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

What will be the result of compiling and executing the following program?


Options are :

  • class Sub gives compilation error
  • BC
  • class Test gives compilation error (Correct)
  • AC

Answer :class Test gives compilation error

What will be the result of compiling and executing Test class?



Options are :

  • None of the above
  • null (Correct)
  • James
  • Compilation error

Answer :null

What will be the result of compiling and executing Test class?


Options are :

  • false (Correct)
  • An exception is thrown at runtime
  • true
  • Compilation error

Answer :false

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

What will be the result of compiling and executing Test class?


Options are :

  • An exception is thrown at runtime (Correct)
  • Compilation error
  • double version: 10.0
  • Double version: 10.0

Answer :An exception is thrown at runtime

Which of the following are Java Exception classes? Select 3 options.


Options are :

  • NumberFormatException (Correct)
  • IllegalArgumentException (Correct)
  • NullException
  • ClassCastException (Correct)
  • ArrayIndexException

Answer :NumberFormatException IllegalArgumentException ClassCastException

Consider the code snippet:


Which of the following statements compile without any warning? Select ALL that apply.


Options are :

  • Line 5
  • Line 9 (Correct)
  • Line 7
  • Line 8 (Correct)
  • Line 6

Answer :Line 9 Line 8

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

Consider below code:

And the commands:

javac Guest.java

java Guest James Gosling


What is the result?


Options are :

  • Some other error as main method can't be invoked manually
  • ArrayIndexOutOfBoundsException is thrown at runtime
  • Welcome Gosling!
  • Welcome James! (Correct)

Answer :Welcome James!

Consider code of Test.java file:

Line 5 is giving compilation error as process method is not found. 

Which of the following method definitions, if used to replace /*INSERT*/, will resolve the compilation error?


Options are :

  • private static String[] process(int [] arr, int start, int end) { return null; }
  • private static String process(int [] arr, int start, int end) { return null; } (Correct)
  • private static int[] process(int [] arr, int start, int end) { return null; }
  • private static int process(int [] arr, int start, int end) { return null; }

Answer :private static String process(int [] arr, int start, int end) { return null; }

What will be the result of compiling and executing Test class?


Options are :

  • Compilation Error
  • String (Correct)
  • CharSequence
  • Object

Answer :String

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

What will be the result of compiling and executing Test class?



Options are :

  • true:false:false:null (Correct)
  • Compilation error
  • false:false:true:null
  • false:false:false:null

Answer :true:false:false:null

What will be the result of compiling and executing Test class?


Options are :

  • An exception is thrown at runtime
  • Compilation error
  • Double version: 20.0
  • double version: 20.0 (Correct)

Answer :double version: 20.0

What will be the result of compiling and executing Test class?


Options are :

  • false false (Correct)
  • false true
  • true false
  • true true

Answer :false false

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

What will be the result of compiling and executing Test class?


Options are :

  • Compilation error (Correct)
  • * ** *** **** *****
  • * ** ***
  • * ** *** ****

Answer :Compilation error

What will be the result of compiling and executing Test class?


Options are :

  • Point(19, 35, -1) Point(19, 40, 0) (Correct)
  • Compilation error
  • Point(17, 35, -1) Point(19, 40, 0)
  • Point(19, 40, 0) Point(19, 40, 0)
  • Point(19, 35, -1) Point(19, 35, -1)
  • Point(17, 35, -1) Point(17, 40, 0)
  • Point(17, 35, -1) Point(17, 35, -1)

Answer :Point(19, 35, -1) Point(19, 40, 0)

Consider below code: 

What will be the result of compiling and executing Test class?


Options are :

  • 2018-1-01
  • 2018-1-1
  • 2018-01-01
  • An exception is thrown at runtime (Correct)

Answer :An exception is thrown at runtime

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

Consider below code: 

What will be the result of compiling and executing Test class?


Options are :

  • [Walnut, Apricot, Almond, Date]
  • Compilation error
  • [Walnut, Date] (Correct)
  • An exception is thrown at runtime

Answer :[Walnut, Date]

What will be the result of compiling and executing Test class?


Options are :

  • Failed
  • Passed
  • Compilation error (Correct)
  • Not a valid score Failed

Answer :Compilation error

What will be the result of executing Test class using below command?

java Test good morning everyone



Options are :

  • good
  • morning
  • Compilation Error (Correct)
  • everyone

Answer :Compilation Error

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

Consider below code: 

What will be the result of compiling and executing Test class?


Options are :

  • [ONE, TWO, THREE]
  • [ONE, TWO]
  • Compilation error (Correct)
  • An exception is thrown at runtime
  • [ONE, TWO, THREE, THREE]

Answer :Compilation error

What will be the result of compiling and executing Test class?


Options are :

  • null
  • Compilation Error
  • NullPointerException
  • Some String containing @ symbol (Correct)

Answer :Some String containing @ symbol

Which of the following keywords is used to manually throw an exception?


Options are :

  • throws
  • catch
  • throw (Correct)
  • thrown

Answer :throw

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

Consider below code: 

What will be the result of compiling and executing Test class?


Options are :

  • Inner
  • Inner Peace! (Correct)
  • Compilation error
  • Peace!

Answer :Inner Peace!

Which of the following array declarations and initializations is NOT legal?


Options are :

  • int [] arr2 = {1, 2, 3, 4, 5};
  • byte [] val = new byte[10];
  • char [] arr1 [] = new char[5][];
  • int [] arr3 = new int[3]{10, 20, 30}; (Correct)

Answer :int [] arr3 = new int[3]{10, 20, 30};

Consider the code of Test.java file:

What will be the result of compiling and executing Test class?


Options are :

  • An exception is thrown at runtime
  • null:0
  • Compilation error (Correct)
  • James:25

Answer :Compilation error

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

What will be the result of compiling and executing Test class?


Options are :

  • Compilation error
  • Output is: (10 != 5)
  • Output is: true (Correct)
  • Output is: false

Answer :Output is: true

What will be the result of compiling and executing Test class?


Options are :

  • Compilation error
  • None of the other options
  • true
  • false (Correct)

Answer :false

Which of these keywords can be used to prevent inheritance of a class?


Options are :

  • super
  • final (Correct)
  • constant
  • class

Answer :final

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

Consider below code: 

What will be the result of compiling and executing Test class?


Options are :

  • true:false:true
  • false:false:false (Correct)
  • false:false:true
  • true:true:true

Answer :false:false:false

Consider below code: 

Which of the following options can replace /*INSERT*/ such that on executing Test class all the array elements are displayed in the output? Select ALL that apply.


Options are :

  • p -> true (Correct)
  • p -> p.length() < 10 (Correct)
  • p -> p.length() >= 1 (Correct)
  • p -> !false (Correct)

Answer :p -> true p -> p.length() < 10 p -> p.length() >= 1 p -> !false

What will be the result of compiling and executing Test class?


Options are :

  • [X, X, Y, Z] (Correct)
  • Exception is thrown at runtime
  • [X, Z]
  • [X, Y, Z]
  • Compilation error
  • [X, X, Z]

Answer :[X, X, Y, Z]

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

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions