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

What will be the output of this program?

1.          public class Whiz {

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

3.           

4.                            for ( int j = 0, k = 5; j < k; k--) ;

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

6.                            for ( int i = 0; i < 5; i++, System.out.print(i + ".Hi ")) ;

7.           

8.                    }

9.          }

 

 


Options are :

  • 1.Hi 2.Hi 3.Hi 4.Hi 5.Hi (Correct)
  • 0.Hi 1.Hi 2.Hi 3.Hi 4.Hi 5.Hi
  • An exception is thrown at runtime.
  • Compilation fails due to an error at line 6.
  • Compilation fails due to multiple errors.

Answer :1.Hi 2.Hi 3.Hi 4.Hi 5.Hi

Which of the following will produce the output 50 40 30 20 10 when inserted at line 6? 

1.          public class Whiz {

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

3.                          L1: for(int i = 5, j = 0; i>0;i--){

4.                                          L2: for(;j<5;j++){

5.                                          System.out.print(i + "" +j +" " );

6.                                          //insert here

7.                                          }

8.                          }

9.                }

10.       }

 

 


Options are :

  • if(j == 0) continue;
  • if(j == 0) continue L1; (Correct)
  • if(j == 0) continue L2;
  • if(j == 0) break L1;
  • None of the above.

Answer :if(j == 0) continue L1;

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

Which of the following will produce the output as 1 3 8 when inserted at line 7 ?

1.          public class Whiz {

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

3.                                         

4.                             int arr[ ][ ] = {{1, 3, 5},{7,8}};

5.                             out:for(int [ ]a : arr){

6.                             for ( int i: a ) {

7.                                      //   insert code here   }

8.                             }

9.                    }

10.         }

 


Options are :

  • if ( i == 7 ) continue; System.out.print(i + " "); if ( i == 3) break out; }
  • if ( i == 7) continue out; System.out.print(i + " "); if ( i == 3) break; }
  • if ( i == 7) continue; System.out.print(i + " "); }
  • if ( i == 7) continue; System.out.print(i + " "); if ( i == 3) break; } (Correct)
  • None of the above.

Answer :if ( i == 7) continue; System.out.print(i + " "); if ( i == 3) break; }

What will be the output of this program?

1.          class A {

2.                   A method() {

3.                           return new A();

4.                   }

5.          }

6.           

7.          class B extends A {

8.                   B method() {

9.                            return new B();

10.              }

11.     }

12.    

13.    class Whiz {

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

15.                      //codes

16.             }

17.   }

 

 


Options are :

  • Compilation succeeds. (Correct)
  • Compilation fails due to an error at line 2.
  • Compilation fails due to an error at line 8.
  • Compilation fails due to multiple errors.

Answer :Compilation succeeds.

What will be the output of this program?

1.          class Animal {

2.                          void eat(){ System.out.print("Animal eats"); }

3.          }

4.          class Bird extends Animal {

5.                          void eat(){ System.out.print("Bird eats"); }

6.                          void print(){ super.eat(); }

7.          }

8.          public class Whiz {

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

10.                                   Bird ab = new Bird();

11.                                   ab.print();

12.                   }

13.      }

 

 


Options are :

  • Animal eats. (Correct)
  • Bird eats.
  • No output.
  • An exception is thrown.
  • Compilation fails.

Answer :Animal eats.

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

Which of the following method will override this method correctly? 

Object supply() { return null; }


Options are :

  • public String supply() throws NullPointerException { return null; } (Correct)
  • int supply() { return 0; }
  • public Object supply()throws Exception { return null; }
  • private Object supply() { return null; }
  • protected Object supply (int x) { return null; }

Answer :public String supply() throws NullPointerException { return null; }

Which of the following statement(s) is/are true?

 I.    One of the main reasons of using inheritance is to promote code reuse. 

 II.   One of the main reasons of using inheritance is to use polymorphism.


 III.  Every java class object pass "is-a" test with Object class. 




Options are :

  • Only I.
  • Only III.
  • Only I and II.
  • Only II and III.
  • All the statements are true. (Correct)

Answer :All the statements are true.

What will be the output of this program? 

1.             interface I { void meth(); }

2.              

3.             class A implements I {

4.                      void A(String s) {

5.                      }

6.                      public void meth() {

7.                               System.out.print("A");

8.                      }

9.             }

10.     

11.        class C extends A implements I {

12.                 public void meth() {

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

14.                 }

15.        }

16.     

17.        class Whiz {

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

19.                          A a = new A();

20.                          C c1 = (C)a;

21.                          c1.meth();

22.                 }

23.         }

 

 


Options are :

  • A
  • C
  • Compilation fails due to an error at line 6.
  • Compilation fails due to multiple errors.
  • An exception will be thrown at run-time. (Correct)

Answer :An exception will be thrown at run-time.

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

What will be the output of this program?

1.        interface Walk {

2.                public default int getSpeed() {

3.                         return 5;

4.                }

5.        }

6.                         

7.        interface Run {

8.                 public default int getSpeed() {

9.                          return 10;

10.            }

11.   }

12.                  

13.   public class Animal implements Walk,Run {

14.                  

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

16.                      Animal an = new Animal();

17.                      System.out.println(an.getSpeed());

18.             }

19.   }

 

 


Options are :

  • 5
  • 10
  • An exception is thrown at run-time.
  • Compilation fails due to an error at line 13. (Correct)
  • Compilation fails due to multiple errors.

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

What will be the output of this program?

1.              public class Whiz {

2.                         

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

4.                                   Move.print();

5.                         }

6.                         

7.                         interface Move {

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

9.                                            System.out.println("Move");

10.                              }

11.                              public static void print(){ }

12.                   }

13.          }

 

 


Options are :

  • Move
  • No output (Correct)
  • Compilation fails due to an error at line 4.
  • Compilation fails due to an error at line 8.
  • Compilation fails due to multiple errors.

Answer :No output

Which of the following statement is true?


Options are :

  • An abstract class must use the abstract keyword when declared (Correct)
  • An abstract class must have one or more abstract methods
  • An abstract class cannot extend a non-abstract class
  • An abstract class can be final.
  • An abstract class doesn't have a constructor

Answer :An abstract class must use the abstract keyword when declared

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

What will be the output of this program?

1.         public class Whiz {

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

3.                                          StringBuilder s =new StringBuilder("1Z0");

4.                                          s.append("-808");

5.                                          System.out.print(s.length() + " ");

6.                                          System.out.print(s.capacity());

7.                          }

8.          }

 

 


Options are :

  • 7 19 (Correct)
  • 7 20
  • 8 19
  • 7 7
  • Compilation fails.

Answer :7 19

Consider the following statements:

I.    StringBuilder sb =new StringBuilder("Java");

II.   StringBuilder sb0 =new StringBuilder("Java");

III.  String s =new String ("Java");

Which of the following option is true? 


Options are :

  • s == sb
  • sb == sb0
  • sb.equals(sb0)
  • s.equals(sb)
  • sb.toString().equals(sb0.toString()) (Correct)

Answer :sb.toString().equals(sb0.toString())

Which of the following statement will compile successfully?


Options are :

  • float f = 21.3D;
  • char ch = "b";
  • char c = 65; (Correct)
  • byte b = 200;
  • boolean b = True;

Answer :char c = 65;

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

Which of the following statement(s) is/are true?

I.    The variables declared inside a method are called member variables.

II.   The instance variables are initialized to their default values.

III.  The variable "x" in the declaration "int x = 10" should be an instance variable. 


Options are :

  • Only I.
  • Only II. (Correct)
  • Only III.
  • Only I and II.
  • Only I and III.

Answer :Only II.

What will be the output of this program?

1.          public class Whiz {

2.                          static int x = 10;

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

4.                                          Whiz wh = new Whiz ();

5.                                          wh.x = 5;

6.                                          int y = x / wh.x;

7.                                          System.out.print("y =");

8.                                          System.out.print();

9.                                          System.out.print(y);

10.                      }

11.        }

 

 


Options are :

  • y =1
  • y =2
  • y = 1
  • Compilation fails due to an error at line 6.
  • Compilation fails due to an error at line 8. (Correct)

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

What will be the output of this program?

1.          class Whiz implements A {

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

3.                                   System.out.print(A.s);

4.                                   System.out.print(A.value);

5.                          }

6.          }

7.          interface A {

8.                          static int value = 15;

9.                          String s = "Value is: ";

10.      }

            

 


Options are :

  • Value is: 15 (Correct)
  • Compilation fails due to an error at line 3.
  • Compilation fails due to an error at line 4.
  • Compilation fails due to multiple errors.
  • An exception will be thrown at runtime.

Answer :Value is: 15

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

Choose the option that contains only primitive literals.


Options are :

  • 1, 'c', "a"
  • 1, 1.5f, True
  • 'BF', 10, "Sure"
  • 1.2D, 1f, 'c' (Correct)
  • None of the above.

Answer :1.2D, 1f, 'c'

Choose the option that contains only primitive data types.


Options are :

  • Float, Byte, char, float
  • Float, Byte, char, float
  • Integer, char, double
  • boolean, char, bit
  • None of the above. (Correct)

Answer :None of the above.

What will be the output of this program?

1.          public class Whiz {

2.                          static int x = 50;

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

4.                                          int x, y = 100;

5.                                          System.out.print(x);

6.                          }

7.          }

 

 


Options are :

  • 50
  • 100
  • 0
  • An Error is thrown at the runtime, stating that, Main method not found in class Whiz.
  • Compilation fails. (Correct)

Answer :Compilation fails.

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

What will be the output of this program?

1.          public class Whiz {

2.           

3.                          int x = y;

4.                          static int y = 10;

5.           

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

7.                                          System.out.print(new Whiz().x + " ");

8.                                          System.out.print(y);

9.                          }

10.    

11.                   static{   y = 15;   }

12.       }

 

 


Options are :

  • 10 15
  • 10 10
  • 15 15 (Correct)
  • Compilation fails due to an error at line 3.
  • Compilation fails due to multiple errors.

Answer :15 15

What will be the output of this program?

1.              public class Whiz {

2.               

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

4.                                         

5.                                          Double d1 = 10.0/0.0;

6.               

7.                                          System.out.print(d1.isInfinite());

8.                          }

9.        }                                                                                                                                         

 

 


Options are :

  • 0.
  • 1.
  • true. (Correct)
  • An Exception is thrown.
  • Compilation fails due to an error at line 7.

Answer :true.

Which of the following statement is valid?


Options are :

  • Long l = 3;
  • Double d = 10;
  • Float f = 1.3;
  • Float f = 3;
  • None of the above. (Correct)

Answer :None of the above.

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

which class of the following will compile and use a default constructor?


Options are :

  • public class Pen { void Pen() { } } (Correct)
  • public class Pen { private Pen() { } }
  • public class Pen { public Pen(String name) { } }
  • public class Pen { public pen() { } }
  • public class Pen { abstract void Pen(); }

Answer :public class Pen { void Pen() { } }

Which of the following statement(s) is\are true about this method signature?

public void main(String s)


Options are :

  • Access level of this method is more restrictive than protected access level.
  • This is the main method.
  • It returns a String.
  • It is an invalid method signature.
  • None of the above. (Correct)

Answer :None of the above.

Which of the following statement is true about this program code?

I.      This code hasn't correctly implemented the encapsulation principals.

II.    Ths "getI" method at line7 has correctly implemented the encapsulation principals but not the variables.

III.   Variables in this code have correctly implemented the encapsulation principals but not the "getI" method.

1.              class Whiz {

2.              public int i;

3.              public char c;

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

5.                                          //codes

6.                          }

7.                          private int getI() {

8.                                          return i;

9.                          }

10.         }         

 

 


Options are :

  • I only (Correct)
  • II only
  • I and II only
  • I and III only
  • None of the statement is true.

Answer :I only

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

What is the result of the following code ?

public class Test {
          public static void main(String[] args) {
                    boolean name = true;
                    switch (name) {
                             case true:
                                       System.out.println("Hello ");
                             default:
                                        System.out.println("hi");
                              }
              }
}

 


Options are :

  • Hello
  • Hi
  • Hello hi
  • Compilation error. (Correct)
  • None of the above.

Answer :Compilation error.

Which of the following represents the correct order from the most to least restrictive?  


Options are :

  • private, protected, default, public
  • public, protected, default, private
  • protected, private, default, public
  • private, default, protected, public (Correct)
  • private, public, default, protected

Answer :private, default, protected, public

What will be the output of this program?

1.      class Whiz {

2.                      private String code = "1Z0-808";

3.                     

4.                      { System.out.print(code+ " "); }

5.                     

6.                      private static int QUESTIONS = 90;

7.                     

8.                      static { System.out.print(QUESTIONS + " "); }

9.                     

10.                 static { QUESTIONS -= 13; System.out.print(QUESTIONS+ " "); }

11.                

12.                 public Whiz() {

13.                                 System.out.println("constructor " );

14.                 }

15. }

16. public class Program {

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

18.                                                 Whiz wh = new Whiz();

19.                 }

20. }

 

 


Options are :

  • 90 77 1Z0-808 constructor (Correct)
  • 1Z0-808 90 77 constructor
  • 90 1Z0-808 77 constructor
  • constructor 90 1Z0-808 77
  • Compilation fails.

Answer :90 77 1Z0-808 constructor

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

What will be the output of this program?

1.        public class Whiz {

2.              

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

4.                          Employer p = new Employer ("Livera" , 22);

5.                          System.out.print(p.age +" ");

6.                          updateAge(p, 30);

7.                          System.out.print(p.age);      

8.                 }

9.              

10.            public static void updateAge(Employer ps, int a) {

11.                     ps.age = a;

12.            }

13.    } 

14.     

15.    class Employer {

16.             Employer(String s, int i) {

17.                     name = s;

18.                     age = i;

19.             }

20.             String name;

21.              int age;

22.     } 

 

 


Options are :

  • 22 22
  • 22 30 (Correct)
  • 30 30
  • 30 22
  • Compilation fails.

Answer :22 30

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions