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

What will the following program print when compiled and run? (Choose one)


Options are :

  • The program will print 0006-01-01.
  • The program will print 2016-01-01. (Correct)
  • The program will not compile.
  • The program will print 2015-01-01.

Answer :The program will print 2016-01-01.

Which array declarations will not compile? (Choose all that apply)


Options are :

  • C. int[] array3 = new int[] {};
  • J. int[][] arr2d4 = new int[4][0];
  • H. int[][] arr2d2 = new int[4][ ];
  • F. int[] array6 = new int[ ] {0,1,2,3};
  • B. int[] array2 = {};
  • A. int[] array1 = new int[0];
  • E. int[] array5 = new int[4] {0,1,2,3}; (Correct)
  • D. int[] array4 = new int[4] {}; (Correct)
  • G. int[] arr2d1[] = new int[4][ ];
  • I. int[][] arr2d3 = new int[ ][4]; (Correct)

Answer :E. int[] array5 = new int[4] {0,1,2,3}; D. int[] array4 = new int[4] {}; I. int[][] arr2d3 = new int[ ][4];

What will be printed when the following program is run? (Choose one)


Options are :

  • 6
  • 13
  • 5 (Correct)
  • 12
  • 7

Answer :5

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

Which statements are true about lambda expressions? (Choose all that apply)


Options are :

  • C. The formal parameters of a lambda expression are local variables in the block scope of the lambda expression. (Correct)
  • D. A local variable declaration in the block scope of a lambda expression can shadow a class member with the same name in the enclosing class. (Correct)
  • B. return statement is mandatory in a lambda expression if the lambda body is a single expression that returns a value.
  • A. A return statement is mandatory in a lambda expression if the lambda body is a statement block.
  • E. A local variable declaration in the block scope of a lambda expression can shadow a local variable with the same name in the enclosing method.

Answer :C. The formal parameters of a lambda expression are local variables in the block scope of the lambda expression. D. A local variable declaration in the block scope of a lambda expression can shadow a class member with the same name in the enclosing class.

Which code can be inserted independently at (1) so that the program prints the following: Free Meal|Free Meal|Free Meal|. (Choose all that apply)


Options are :

  • A. for (StringBuilder meal : meals) meal.insert(0, "Free Meal"); (Correct)
  • E. for (StringBuilder meal : meals) meal.append("Free Meal"); (Correct)
  • C. StringBuilder freeMeal = new StringBuilder("Free Meal"); for (StringBuilder meal : meals) meal = freeMeal;
  • F. for (StringBuilder meal : meals) meal = meal.append("Free Meal"); (Correct)
  • D. for (StringBuilder meal : meals) meal = new StringBuilder("Free Meal");
  • B. for (StringBuilder meal : meals) meal = meal.insert(0, "Free Meal"); (Correct)

Answer :A. for (StringBuilder meal : meals) meal.insert(0, "Free Meal"); E. for (StringBuilder meal : meals) meal.append("Free Meal"); F. for (StringBuilder meal : meals) meal = meal.append("Free Meal"); B. for (StringBuilder meal : meals) meal = meal.insert(0, "Free Meal");

Which expressions will evaluate to true if preceded by the following code? (Choose all that apply)

String a = "hello";

String b = new String(a);

String c = a;

char[] d = { 'h', 'e', 'l', 'l', 'o' };


Options are :

  • a.equals(b) (Correct)
  • (a == "Hello")
  • (a == b)
  • (a == c) (Correct)
  • a.equals(d)

Answer :a.equals(b) (a == c)

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

What is the output from running the following program? (Choose one)


Options are :

  • The program will execute indefinitely, printing all odd numbers from 3 and upward.
  • The program will execute indefinitely, printing all even numbers from 2 and upward.
  • The program will execute indefinitely, printing all numbers from 2 and upward.
  • The program will execute indefinitely, printing all odd numbers from 1 and upward. (Correct)
  • The program will execute indefinitely, printing all numbers from 1 and upward.
  • The program will execute and terminate normally, but will not print anything.

Answer :The program will execute indefinitely, printing all odd numbers from 1 and upward.

What will be the result of compiling and running the following program? (Choose one)


Options are :

  • The program will fail to compile because of the line marked (1).
  • The program will fail to compile because of the line marked (2).
  • The program will fail to compile because of the line marked (4).
  • The program will fail to compile because of the line marked (3).
  • The program will compile and run without any problems. (Correct)

Answer :The program will compile and run without any problems.

Which statement about the following program is true? (Choose one)


Options are :

  • The program will fail to compile.
  • The program will print one arguments and four arguments when called with zero and three program arguments, respectively.
  • The program will throw a NullPointerException when run with no program arguments.
  • The program will print no arguments and two arguments when called with zero and three program arguments, respectively.
  • The program will print no arguments and four arguments when called with zero and three program arguments, respectively. (Correct)
  • The program will print no arguments and three arguments when called with zero and three program arguments, respectively.

Answer :The program will print no arguments and four arguments when called with zero and three program arguments, respectively.

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

What is the output from running the following program? (Choose one)


Options are :

  • false,false,false
  • The program will fail to compile.
  • false,true,false
  • The program will compile, but will throw a runtime exception.
  • false,false,true (Correct)
  • false,true,true

Answer :false,false,true

What will the following program print when compiled and run? (Choose one)


Options are :

  • The program compiles and prints: Number passed. (Correct)
  • The program fails to compile, because the call to the callType() method is ambiguous.
  • The program compiles and prints: Object passed.
  • None of the above.

Answer :The program compiles and prints: Number passed.

What would be the result of compiling and running the following program? (Choose one)


Options are :

  • The program will fail to compile, since the argument args passed to the static method main() cannot be passed to the non-static method func().
  • The program will compile, but will throw an exception when run.
  • The program will fail to compile, since the non-static method func() cannot access the static variable ref.
  • The program will fail to compile, since the static method main() cannot have a call to the non-static method func().
  • The program will compile and run successfully. (Correct)

Answer :The program will compile and run successfully.

Java Certification (1Z0-815) Exam Simulation [2020] Set 1

What will be the result of attempting to compile and run the following program? (Choose one)


Options are :

  • The program will print eeny miny mo at runtime. (Correct)
  • The program will print meeny miny mo at runtime.
  • The program will fail to compile.
  • The program will print eeny meeny miny at runtime.
  • The program will print eeny meeny miny mo at runtime.

Answer :The program will print eeny miny mo at runtime.

Given the following member declarations, which statement is true? (Choose one)


Options are :

  • Declarations (2) and (3) cannot occur in the same class declaration.
  • Declarations (2) and (4) cannot occur in the same class declaration.
  • Declarations (1) and (4) cannot occur in the same class declaration. (Correct)
  • Declarations (1) and (3) cannot occur in the same class declaration.

Answer :Declarations (1) and (4) cannot occur in the same class declaration.

Which statements are true about the value of a field, when no explicit initial value has been assigned? (Choose all that apply)


Options are :

  • The value of all fields that are references is null. (Correct)
  • The value of a field of type int is undetermined.
  • A field of type String will denote the empty string ("").
  • The compiler may issue an error if the field is used in a method before it is initialized.
  • The value of a field of any numeric type is 0. (Correct)

Answer :The value of all fields that are references is null. The value of a field of any numeric type is 0.

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

Which is the first line in the following code after which the object created in the line marked (0) will be a candidate for garbage collection, assuming no compiler optimizations are done? (Choose one)


Options are :

  • The line marked (3)
  • The line marked (6)
  • The line marked (2)
  • The line marked (4) (Correct)
  • The line marked (5)
  • The line marked (1)

Answer :The line marked (4)

What will the following program print when compiled and run? (Choose one)


Options are :

  • The program will not compile.
  • The program will throw a NullPointerException.
  • The program will print: [Ada, Otto, Alyla, Anna] [Anna, Alyla, Otto, Ada]
  • The program will print: [Alyla, Ada, Otto, Anna] [Anna, Otto, Ada, Alyla] (Correct)

Answer :The program will print: [Alyla, Ada, Otto, Anna] [Anna, Otto, Ada, Alyla]

Which of the following implementations of a max() method will correctly return the largest value? (Choose one)


Options are :

  • Implementation labeled (1)
  • Implementation labeled (2)
  • Implementation labeled (3)
  • Implementation labeled (4) (Correct)

Answer :Implementation labeled (4)

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

What will be the result of attempting to compile and run the following program? (Choose one)


Options are :

  • The program will print 9 and terminate normally.
  • The program will print 10 and terminate normally.
  • The program will fail to compile. (Correct)
  • The program will not terminate normally.
  • The program will print 0 and terminate normally.

Answer :The program will fail to compile.

Which statements will compile without errors? (Choose all that apply)


Options are :

  • C. double d = 0B1111_1111D;
  • E. int date1 = Integer.parseInt("_2014_01_11"); (Correct)
  • B. byte b = 0B1111_1111;
  • F. int date2 = _2014_01_11;
  • D. Double dRef = 3_____141.592_653_589_793e-3; (Correct)
  • A. Integer iRef = 0b111_000; (Correct)
  • G. long date3 = 2014_01_11_L;

Answer :E. int date1 = Integer.parseInt("_2014_01_11"); D. Double dRef = 3_____141.592_653_589_793e-3; A. Integer iRef = 0b111_000;

Which of these expressions are legal? (Choose all that apply)


Options are :

  • ('c' + 'o' + 'o' + 'l') (Correct)
  • ("co" + new String('o' + 'l'))
  • ("co" + new String("co")) (Correct)
  • ("co" + "ol") (Correct)
  • "co".concat("ol") (Correct)

Answer :('c' + 'o' + 'o' + 'l') ("co" + new String("co")) ("co" + "ol") "co".concat("ol")

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

What will be the result of attempting to compile and run the following program? (choose one)


Options are :

  • The program will compile correctly and will print the following at runtime: It's OK.
  • The program will compile, but will throw a runtime exception.
  • The program will compile correctly and will print the following at runtime: It's OK. I am not OK. You are OK.
  • The program will fail to compile. (Correct)
  • The program will compile correctly and will print the following at runtime: It's OK. I am not OK.

Answer :The program will fail to compile.

What will be the result of attempting to run the following program? (Choose one)


Options are :

  • The program will throw an ArrayIndexOutOfBoundsException and terminate. (Correct)
  • The program will print 6.
  • The program will print 7.
  • The program will print 4.
  • The program will throw a NullPointerException and terminate.

Answer :The program will throw an ArrayIndexOutOfBoundsException and terminate.

Which expression statements, when inserted at (1), will cause the following class to compile without errors? (Choose all that apply)


Options are :

  • c++ (Correct)
  • b++ (Correct)
  • d++
  • e++ (Correct)
  • a++ (Correct)

Answer :c++ b++ e++ a++

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

Given the class

what would be the result of executing the following command line? (Choose one)

      >java Args In politics stupidity is not a handicap


Options are :

  • The program will print Args handicap.
  • The program will print Args a.
  • The program will print In a.
  • The program will throw an ArrayIndexOutOfBoundsException.
  • The program will print In handicap. (Correct)
  • The program will print java handicap.

Answer :The program will print In handicap.

Which main() method will succeed in printing the last program argument and terminate normally with no output, if no program arguments are specified? (Choose one)


Options are :

  • A. public static void main(String[] args) { if (args.length != 0) System.out.println(args[args.length-1]); } (Correct)
  • C. public static void main(String[] args) { int ix = args.length; String last = args[ix]; if (ix != 0) System.out.println(last); }
  • D. public static void main(String[] args) { int ix = args.length-1; if (ix > 0) System.out.println(args[ix]); }
  • E. public static void main(String[] args) { try { System.out.println(args[args.length-1]); } catch (NullPointerException e) {} }
  • B. public static void main(String[] args) { try { System.out.println(args[args.length]); } catch (ArrayIndexOutOfBoundsException e) {} }

Answer :A. public static void main(String[] args) { if (args.length != 0) System.out.println(args[args.length-1]); }

Which of these combinations of switch expression types and case label value types are legal within a switch statement? (Choose all that apply)


Options are :

  • G. switch expression of type byte and case label value of type Byte
  • F. switch expression of type Byte and case label value of type byte (Correct)
  • B. switch expression of type float and case label value of type int
  • A. switch expression of type int and case label value of type char (Correct)
  • C. switch expression of type byte and case label value of type float
  • E. switch expression of type boolean and case label value of type boolean
  • D. switch expression of type char and case label value of type long
  • H. switch expression of type String and case label value of type String (Correct)

Answer :F. switch expression of type Byte and case label value of type byte A. switch expression of type int and case label value of type char H. switch expression of type String and case label value of type String

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

Which statement about the switch construct is true? (Choose one)


Options are :

  • A character literal can be used as a value for a case label. (Correct)
  • The keyword continue can never occur within the body of a switch statement.
  • All switch statements must have a default label.
  • No case label may follow a default label in a single switch statement.
  • A statement within a switch statement can have only one case label.

Answer :A character literal can be used as a value for a case label.

Given the following code, which statement is true?


Options are :

  • The program will fail to compile if the break statement is replaced by an empty statement.
  • The program will fail to compile if the break statement is replaced by the return statement.
  • The program will print 4, 3 at runtime, if the break statement is replaced by the continue statement. (Correct)
  • The program will print 3, 3 at runtime.
  • The program will fail to compile.

Answer :The program will print 4, 3 at runtime, if the break statement is replaced by the continue statement.

What will be the result of attempting to compile and run the following code? (Choose one)


Options are :

  • The program will print 0.
  • The program will print 2.
  • The program will print 3.
  • The program will print 1.
  • The program will fail to compile. (Correct)

Answer :The program will fail to compile.

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

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions