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

What will be the output of this program?

1.       public class Whizlab {

2.                public static void main(String[] args) throws java.io.IOException {

3.                         String s1 = "Whizlab";

4.                         s1.substring(1, 4);

5.                         System.out.println(s1.charAt(3));

6.               }

7.       }

 


Options are :

  • z (Correct)
  • l
  • a
  • An Exception will be thrown.
  • Compilation fails due to multiple errors.

Answer :z

Which of these methods of the String class can be used to check whether a given object starts with a particular string literal?   


Options are :

  • endsWith()
  • beginWith()
  • startsWith() (Correct)
  • Contain()
  • starts()

Answer :startsWith()

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

Which value is returned by compareTo() method if the invoking string is greater than the string compared?   


Options are :

  • 0
  • value less than zero
  • value greater than zero (Correct)
  • None of the above.

Answer :value greater than zero

What will be the output of this program code?

1.        public class Whizlab {

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

3.                          StringBuilder sb = new StringBuilder("ab");

4.                           sb.append("cd");

5.                           String str = new String(sb);

6.                           str.concat("ef");

7.                           System.out.println(str);

8.                }

9.       }

 


Options are :

  • ab
  • abcd (Correct)
  • abcdef
  • Compilation fails due to an error at line 5.
  • Compilation fails due to multiple errors.

Answer :abcd

What will be the output of this program code?

1.       public class Whizlab {

2.                public static void main(String [] args)throws java.io.IOException {

3.                         StringBuilder sb = new StringBuilder("Whiz");

4.                         sb.append(new char[]{'l','a','b'}, 0, 2);

5.                         System.out.println(sb);

6.                }

7.       }

 


Options are :

  • Whiz
  • Whizla (Correct)
  • Whizlab
  • An exception will be thrown.
  • Compilation fails

Answer :Whizla

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

What will be the output of this program code?

1.       public class Whizlab {

2.                public static void main(String [] args)throws java.io.IOException {

3.                         StringBuilder sb = new StringBuilder("Whiz");

4.                         sb.delete(2, 5);

5.                         System.out.println(sb);

6.                }

7.       }

 


Options are :

  • Wh (Correct)
  • Whi
  • Whiz
  • An Exception will be thrown.
  • Compilation fails.

Answer :Wh

What will be the output of this program code?

1.      import java.time.LocalTime;

2.      import java.time.temporal.ChronoUnit;

3.      class Whizlab { 

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

5.                         LocalTime lt  = LocalTime.of(22,10);

6.                         lt = lt.truncatedTo(ChronoUnit.HALF_DAYS);

7.                        System.out.println(lt);

8.                }

9.      }

 


Options are :

  • 22:10
  • 12:00 (Correct)
  • 18:00
  • An Exception will be thrown.
  • Compilation fails.

Answer :12:00

What will be the output of this program code?

1.      import java.time.LocalDate;

2.              

3.      class Whizlab {            

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

5.                         LocalDate ld = LocalDate.ofYearDay(2016, 22);

6.                         System.out.println(ld.getMonthValue());

7.                }

8.      }

 


Options are :

  • 22
  • 0
  • 1 (Correct)
  • An Exception is thrown.
  • Compilation fails.

Answer :1

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

Given:

char [ ] chars = {'A', 'B', '1', '2', '@'};

Which of the following can access the value of @ in this given array? 


Options are :

  • chars[3];
  • chars[5];
  • chars[chars.last];
  • chars[chars.length-1]; (Correct)
  • Given array is invalid.

Answer :chars[chars.length-1];

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

What will be the output of this program?

1.      class Program {

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

3.                       int a [ ] = { 1,2,053,4};

4.                       int b [ ][ ] = { {1,2,4} , {2,2,1},{0,43,2}};

5.                       System.out.print(a[3] == b[0][2] );

6.                       System.out.print(" " + (a[2] == b[2][1]));

7.                      }

8.      }


Options are :

  • true false
  • false false
  • true true
  • true true (Correct)
  • Compilation fails

Answer :true true

What will be the output of this program code?

1.      class Program {

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

3.                                       int ints [ ][ ] = new int[3][ ];

4.                                       ints[1] = new int[ ]{1,2,3};

5.                                       ints[2] = new int[ ]{4,5};

6.                                       System.out.print(ints[1][1]);

7.                      }

8.       }         


Options are :

  • 2 (Correct)
  • 3
  • 5
  • Compilation fails due to error at the line 3.

Answer :2

What will be the output of this program?

1.             public class Program {

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

3.              

4.                             int []ints = new int[0b101];

5.                             int len = ints.length;

6.                            

7.                             for(int i : ints)

8.                             System.out.print(i);

9.                 }

10.         }


Options are :

  • 00000 (Correct)
  • 0000
  • nullnullnullnull
  • A NullPointerException is thrown.
  • Compilation fails due to error at line 4.

Answer :00000

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

What will be the output of this program?

1.             public class Program { 

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

3.                             String [ ][ ] strings = {{"1","0"},{"Z","8","1"},{"-"}};

4.                             System.out.print(strings[0][0] + strings[1][0] + strings[0][1]+

5.                                                             strings[2][0]+strings[1][1]+strings[1][2]+strings[0][1]);

6.                 }

       }


Options are :

  • 1Z1-808
  • 1Z0-810 (Correct)
  • 1Z1-801
  • 1Z0-801
  • An ArrayIndexOutOfBoundsException is thrown.

Answer :1Z0-810

What will be the output of this program code?

1.             import java.util.Arrays;

2.              

3.             public class Program {

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

5.                               String[ ][ ] strings = {{"A","Z"},{"C","D","S"},{"L"}};

6.                               Arrays.sort(strings);

7.                               for(String [ ]str : strings) {

8.                                       for(String s :  str) {

9.                                               System.out.print(s);

10.                                  }

11.                           }

12.                  }

13.          }


Options are :

  • ACDLSZ
  • ZSLDCA
  • A ClassCastException is thrown. (Correct)
  • An ArrayIndexOutOfBoundsException is thrown.
  • Compilation fails.

Answer :A ClassCastException is thrown.

Which of the following statement is true?   


Options are :

  • All classes of Exception extend Error.
  • All classes of Error extend Exception.
  • Checked Exceptions must be handled or declared to be thrown. (Correct)
  • Runtime Exceptions must be handled or declared to be thrown.
  • None of the above.

Answer :Checked Exceptions must be handled or declared to be thrown.

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

1.             public class Program{

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

3.                                new Program().doIt();  

4.                                new Program().didIt();

5.                       }

6.                         

7.                       static void doIt()throws java.io.IOException {

8.                                 throw new java.io.IOException();

9.                       }

10.                                  

11.                  static void didIt()throws ClassNotFoundException{

12.                            throw new SecurityException();

13.                  }

14.        }                             

                                                                                                          

Which of the following will compile the above code successfully when inserted at line 2?


Options are :

  • public static void main(String [ ] args)throws java.io.IOException, ClassNotFoundException { (Correct)
  • public static void main(String [ ] args)throws java.io.IOException, SecurityException
  • public static void main(String [ ] args)throws java.io.IOException|SecurityException
  • public static void main(String [ ] args)throws ClassNotFoundException {
  • None of the above.

Answer :public static void main(String [ ] args)throws java.io.IOException, ClassNotFoundException {

What will be the output of this program when the given command line invocation is java Program 10

1.          class Program {

2.                    static Integer I;

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

4.                             String s;

5.                             try {

6.                                     s = I.toString();

7.                             } finally {

8.                                     try {

9.                                              int i = Integer.parseInt(args[0]);

10.                                 } catch(NumberFormatException E) {

11.                                         System.out.print("NumberFormat ");

12.                                 } finally {

13.                                         System.out.print("Fin2 ");

14.                                 }

15.                                System.out.print("Fin1 ");

16.                       }

17.               }

18.         }


Options are :

  • NumberFormat Fin1 Fin2
  • NumberFormat Fin1
  • NumberFormat Fin2
  • Fin1 Fin2
  • Fin2 Fin1 followed by uncaught exception (Correct)

Answer :Fin2 Fin1 followed by uncaught exception

Which of the following exception is thrown by the JVM when code uses an illegal index to access an array?   


Options are :

  • NullPointerException
  • NumberFormatException
  • IllegalArgumentException
  • ClassCastException
  • ArrayIndexOutOfBoundsException (Correct)

Answer :ArrayIndexOutOfBoundsException

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

Complete the statement :

___________________ is thrown by the programmer to indicate that a method has passed an illegal or inappropriate argument.


Options are :

  • NullPointerException
  • NumberFormatException
  • IllegalArgumentException (Correct)
  • ClassCastException
  • ArrayIndexOutOfBoundsException

Answer :IllegalArgumentException

What will be the output of this program code?

1.          public class Program {

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

3.                              Object obj = new Double(3);

4.                               Number num = (Number) obj;

5.                               System.out.println(num);

6.                    }

7.           }


Options are :

  • 3.0 (Correct)
  • ClassCastException
  • IllegalArgumentException
  • NumberFormatException
  • Compilation fails

Answer :3.0

Which of the following is a valid way of compiling java source file with the name "Whizlabs"?   


Options are :

  • javac Whizlabs.class
  • javac Whizlabs.java (Correct)
  • java Whizlabs.java
  • javac Whizlabs
  • java Whizlabs.class

Answer :javac Whizlabs.java

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

What will be the output of this program? 

1.      public class Whiz {

2.                     

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

4.                        System.out.println("Main ");

5.               }

6.                     

7.               {    System.out.println("Whiz "); };

8.                     

9.               static{ System.out.print("Static "); };

10.      }


Options are :

  • Static Main (Correct)
  • Whiz Static Main
  • Whiz Main
  • Main
  • Compilation fails.

Answer :Static Main

A Java class must always have  _________ .   


Options are :

  • A main method.
  • Variable(s).
  • At least one method.
  • A Constructor. (Correct)
  • All of the above.

Answer :A Constructor.

Which of the following is used for the java doc comments?   


Options are :

  • // comments
  • /* comments */
  • /// comments
  • 'comments
  • /** comments*/ (Correct)

Answer :/** comments*/

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

What will be the output of this program?

1.      public class Whiz {

2.                     

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

4.                        int x = 2;

5.                        for ( int x = 0; x < 3; x++ ) {

6.                                 System.out.print(x);

7.                       }             

8.              }

9.      }


Options are :

  • 0123
  • 012
  • 123
  • 222
  • Compilation fails. (Correct)

Answer :Compilation fails.

What will be the output of this program code?

1.      public class Whiz {

2.                     

3.               static int x = 10;

4.                     

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

6.                        for ( x = 1; x < 3; x++ ) {

7.                                System.out.print(x);

8.                        }             

9.                        System.out.println(x);

10.           }

11.    }


Options are :

  • 12310
  • 1210
  • 123 (Correct)
  • 10
  • Compilation fails.

Answer :123

Suppose that you need to create a class to store information about Books contained in a library.

What will be the scope of the variable that stores the ISBN of a book?


Options are :

  • Method parameter
  • Instance variable (Correct)
  • Static variable
  • Global variable
  • Local variable

Answer :Instance variable

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

Which of the following is a valid top level class declaration?   


Options are :

  • class switch{ }
  • public static class Test{}
  • protected class Test{ }
  • private class Test{ }
  • None of the above. (Correct)

Answer :None of the above.

Which of the following statement specifies that file belongs to the package com.whizlabs.exams?   


Options are :

  • pack com.whizlabs.exams;
  • package com.whizlabs.exams.*;
  • pack com.whizlabs.exams.*;
  • package com.whizlabs.exams; (Correct)
  • package com.whizlabs.*;

Answer :package com.whizlabs.exams;

What will be the output of this program?

1.       import static  java.lang.System.*;

2.        

3.       public class Whizlabs {

4.                     

5.                 static int x = 10;

6.                     

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

8.                          out.println(x);

9.                 }

10.     }


Options are :

  • 10 (Correct)
  • No output will be produced.
  • Compilation fails due to error at line 1.
  • Compilation fails due to error at line 8.
  • Compilation fails due to multiple errors.

Answer :10

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

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions