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

What will be the output of this program?

1.  import java.time.LocalDate;

2.  import java.time.format.DateTimeFormatter;

3. 

4.  public class Whizlab {

5.           public static void main(String[] args) {   

6.                    LocalDate ldt = LocalDate.of(2000,3,1);

7.                    DateTimeFormatter format = DateTimeFormatter.ofPattern("dd/M/yyyy");

8.                    System.out.println(ldt.format(format));

9.           }

10.  }


Options are :

  • 1/3/2000
  • 01/03/2000
  • 01/3/2000 (Correct)
  • An Exception is thrown.
  • Compilation fails.

Answer :01/3/2000

Which of the following formatting string can be used to format date string to following format?

25 Dec 2015


Options are :

  • d MMM uuuu (Correct)
  • dd M yy
  • dd MM uuuu
  • d MM yyyy
  • None of the above.

Answer :d MMM uuuu

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

What will be the output of this program?

1.      import java.time.LocalDate;

2.      import java.time.temporal.ChronoField;

3.       

4.      public class Whizlab{

5.                        public static void main(String[] args) {

6.                                      LocalDate ld = LocalDate.of(2015, 12, 12);

7.                                      ld = ld.with(ChronoField.DAY_OF_YEAR,30);

8.                                      System.out.println(ld);

9.                        }   

10.   }

 

 


Options are :

  • 2015-12-12
  • 2015-01-30 (Correct)
  • 2015-12-30
  • An Exception will be thrown.
  • Compilation fails.

Answer :2015-01-30

Given

1.      import java.time.LocalTime;

2.      import java.time.temporal.ChronoField;

3.       

4.      public class Whizlab{

5.                        public static void main(String[] args) {

6.                                      LocalTime lt = LocalTime.of(2,2,15);

7.                                      System.out.println(lt.getLong(ChronoField.valueOf("MINUTE_OF_DAY")));

8.                        }   

9.     

 

What is the output?


Options are :

  • 122 (Correct)
  • 842
  • 2
  • An Exception.
  • Compilation fails.

Answer :122

What will be the output of this program?

1.      import java.util.ArrayList;

2.      import java.util.List;

3.       

4.      public class Whizlab{

5.                     

6.                      public static void main(String[] args){   

7.                                      List<String> list = new ArrayList<String>();

8.                                      list.add("1");

9.                                      list.add("2");

10.                                 list.add("3");

11.                                 list.add("4");

12.                                

13.                                 System.out.println(list.set(3,"3"));

14.                 }

15.   }

 

 


Options are :

  • 4 (Correct)
  • 3
  • -1
  • An Exception is thrown.
  • Compilation fails.

Answer :4

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

Consider the code:

What is the result ?


Options are :

  • 68 (Correct)
  • 6789
  • 678
  • 679

Answer :68

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

Consider the following code:

What is the result ?


Options are :

  • Equal By Content (Correct)
  • Compilation Fails.
  • Equal By Address
  • Not Equal either by Address or by Content

Answer :Equal By Content

Consider the code:

What is the result?


Options are :

  • 10
  • The Compilation Fails. (Correct)
  • 10203040
  • Nothing is printed to the console.

Answer :The Compilation Fails.

To access all elements of an array in reverse order, which loop cannot be used?


Options are :

  • for-each loop. (Correct)
  • standard for loop.
  • do-while loop.
  • do-while loop.

Answer :for-each loop.

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

Consider the following code:

What is the result?


Options are :

  • 101001000
  • 10
  • Nothing will be printed to the console. (Correct)
  • 10100

Answer :Nothing will be printed to the console.

Consider the following code:

What is the result?


Options are :

  • B (Correct)
  • Compilation Fails as we are taking default case at the beginning.
  • AB
  • ABCD

Answer :B

Consider the code:

What is the result?


Options are :

  • Nothing is printed to the console.
  • The Compilation Fails.
  • 10203040
  • 10 (Correct)

Answer :10

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

Consider the following code:

What is the result?


Options are :

  • ABCD
  • Compilation Fails as we are taking default case at the beginning.
  • AB (Correct)
  • B

Answer :AB

Consider the following code:

What is the result ?


Options are :

  • Compilation Fails as else keyword missing.
  • AC
  • BC (Correct)
  • ABC

Answer :BC

Consider the code:

Which of the following command invocations will print Java Basics to the console ?


Options are :

  • java Books Python "Java Basics" (Correct)
  • java Books Python Java Basics
  • java Books "Java Basics" Python Basics
  • java Books Java Basics Python Basics

Answer :java Books Python "Java Basics"

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

Consider the code:

What is the result?


Options are :

  • Loop never terminates and it is infinite loop.
  • 13579
  • Compilation Fails because we cannot use while loop inside do-while loop.
  • 3 (Correct)

Answer :3

Consider the code:

What is the result?


Options are :

  • 1
  • 0
  • 2
  • 6 (Correct)

Answer :6

Consider the following code:

What is the result?


Options are :

  • 101001000
  • 10
  • Compilation Fails. (Correct)
  • 10100

Answer :Compilation Fails.

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

Consider the code:

What is the result?


Options are :

  • An exception is thrown at runtime.
  • The Compilation Fails (Correct)
  • Hello
  • Hi

Answer :The Compilation Fails

Which of the following is True?


Options are :

  • A switch statement can have atleast one case statement and atleast one default statement.
  • A switch statement can have any number of case statements and atmost one default statement. (Correct)
  • A switch statement can have atmost one case statement and atleast one default statement.
  • A switch statement can have atleast one case statement and atmost one default statement.

Answer :A switch statement can have any number of case statements and atmost one default statement.

Consider the code:

What is the result ?


Options are :

  • It prints durga102030 (Correct)
  • It prints durga60
  • An exception is thrown at runtime
  • Compilation Fails

Answer :It prints durga102030

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

Consider the following code:

What is the result ?


Options are :

  • The Compilation Fails. (Correct)
  • 1 2 3 4 5
  • It is infinite loop and it keep on printing 1 2 3 4 5 ...
  • 1 2 3 4

Answer :The Compilation Fails.

Consider the code:

What is the result?


Options are :

  • Cat Dog Rat
  • An ArrayIndexOutOfBoundsException is thrown at runtime. (Correct)
  • The compilation fails.
  • Cat Dog

Answer :An ArrayIndexOutOfBoundsException is thrown at runtime.

Consider the code :

What is the result ?


Options are :

  • Nothing will be printed to the console.
  • x is >20
  • x is > 5
  • The Compilation Fails. (Correct)

Answer :The Compilation Fails.

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

Consider the following code:

Which of the following can be inserted independently in Line-1 without causing any compile time error ?


Options are :

  • case y: System.out.println(y); (Correct)
  • case x+2*y: System.out.println(x+2*y);
  • case 10+20+30: System.out.println(60); (Correct)
  • case x: System.out.println(x);

Answer :case y: System.out.println(y); case 10+20+30: System.out.println(60);

Which of the following are valid main method declarations?


Options are :

  • public static void main(String[] args) (Correct)
  • public static void Main(String args)
  • public static void main(String args)
  • public static void main(String... args) (Correct)

Answer :public static void main(String[] args) public static void main(String... args)

Which of the following are TRUE about switch statement ?


Options are :

  • case label should be within the range of switch argument type.
  • case label should be constant expression.
  • Duplicate case labels are not allowed.
  • We can take default case anywhere.
  • All of these. (Correct)

Answer :All of these.

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

Consider the code:

What is the output:


Options are :

  • 012
  • 000 (Correct)
  • The Compilation fails.
  • 123

Answer :000

Which of the following statement is true?

1.              public class Whiz {

2.                           static int i = 2;

3.                           public static void main(String [ ] args) {

4.                                          int array[ ] = new int[i];

5.                                          array[1] = 66;

6.                                          array[2] = 67;

7.                                          System.out.print(array[1]);

8.                          }

9.              }


Options are :

  • The output will be 66.
  • The output will be "C".
  • The output will be 67.
  • An Exception will be thrown at the runtime. (Correct)
  • Compilation fails as we can't assign int values to the elements of a char array.

Answer :An Exception will be thrown at the runtime.

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

What is the output of this program code?

1.              public class Whiz {

2.                         public static void main(String [ ] args) {

3.                                          long [ ][ ] l2d;

4.                                          long [ ] l1d = {1,2,3};

5.                                          Object o = l1d;

6.                                          l2d = new long[3][3];

7.                                          l2d[0][0] = (long[])o;

8.                          }

9.             }                                                     

 


Options are :

  • Compilation fails due to an error at line 5.
  • Compilation fails due to an error at line 6.
  • Compilation fails due to an error at line 7. (Correct)
  • Compilation succeeds and the code runs without exception.
  • Compilation succeeds and an exception is thrown at runtime.

Answer :Compilation fails due to an error at line 7.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions