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.                                     

5.                         do{

6.                                   int i = 1;

7.                                  System.out.print(i++ + "");

8.                         } while(i <= 5);

9.              }

10.     }         



Options are :

  • 11111
  • 12345
  • 123456
  • An infinite loop
  • Compilation fails (Correct)

Answer :Compilation fails

What will be the output of this program?

1.             public class Whizlabs {

2.                            

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

4.                               int x = 10;

5.                            

6.                               if (x > 10);

7.                                        System.out.println(">");

8.                               else if(x < 10)

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

10.                   }

11.          }


Options are :

  • >
  • <
  • ><
  • No output.
  • Compilation fails (Correct)

Answer :Compilation fails

What will be the output of this program code?

1.      public class Whiz {

2.                     

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

4.                                     

5.                          final int x = 0;

6.                          final int y = 2;

7.                     

8.                          switch(x+y) {

9.                                                  case x    : {System.out.print("A");}

10.                                             case 1    : System.out.print("B");

11.                                             default : System.out.print("default"); break;

12.                                             case y    : System.out.print("C");

13.                     }

14.           }

15.    }


Options are :

  • ABdefault
  • default
  • defaultC
  • C (Correct)
  • Compilation fails

Answer :C

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

What will be the output of this program code?

1.      public class Whiz{

2.                     

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

4.                                     

5.                                      final int x;

6.                                      x = 0;

7.                                      final int y = 2;

8.                     

9.                                      switch(x) {

10.                                                 case x    : {System.out.print("A");}

11.                                                 case 1    : System.out.print("B");

12.                                                 default : System.out.print("default"); break;

13.                                                 case y    : System.out.print("C");

14.                                 }

15.                 }

16. }


Options are :

  • ABdefault
  • default
  • defaultC
  • C
  • Compilation fails (Correct)

Answer :Compilation fails

Which of the following data type cannot be used in switch expression?   


Options are :

  • char
  • enum
  • String
  • long (Correct)
  • None of the above

Answer :long

What will be the output of this program?

1.      public class Whiz {

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

3.                        String out = "0";

4.                        int i = -1, j = -5;

5.                        if(i < 5)

6.                        if(j > 0)

7.                        if(i > j)

8.                        out += "1";

9.                        else out += "2";

10.                   else out += "3";

11.                   else out += "4";

12.                   System.out.println(out);

13.          }

}What will be the output of this program?

1.      public class Whiz {

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

3.                        String out = "0";

4.                        int i = -1, j = -5;

5.                        if(i < 5)

6.                        if(j > 0)

7.                        if(i > j)

8.                        out += "1";

9.                        else out += "2";

10.                   else out += "3";

11.                   else out += "4";

12.                   System.out.println(out);

13.          }

14. }


Options are :

  • 01
  • 02
  • 03 (Correct)
  • 04
  • Compilation Error

Answer :03

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

What will be the output of this program?

Given :

1.      public class Whiz {

2.                     

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

4.                       

5.                       int _6 = 6;

6.                                    

7.                       if(_6 > 6)

8.                            System.out.print(">6");              

9.                            System.out.print(" or ");

10.                  else {

11.                       System.out.print("<6");

12.                  }

13.         }

14. }


Options are :

  • >6 or
  • <6
  • or <6
  • No output.
  • Compilation fails (Correct)

Answer :Compilation fails

Which of the following statement is true?

I.            If statement must contain else or else if.

II.           We can't place any other statements between if and else (or else if) blocks.

III.          If statement may have more than one else statements.


Options are :

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

Answer :Only II.

Choose the option that is equivalent to this if-then-else statement:

      int x = 1; 
      if ( x > 1 ) {
             System.out.println(">");
       } else if ( x < 1 ) {
             System.out.println("<");
       } else {
             System.out.println("=");
       }


Options are :

  • System.out.println(x>1?">":x<1?"<":"="); (Correct)
  • System.out.println(x>1?">":"<":"=");
  • System.out.println(x>1?">"?"<":"=");
  • System.out.println(x>1?">"?"<"?"=");
  • None of the above

Answer :System.out.println(x>1?">":x<1?"<":"=");

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

 What will be the output of this program code?

1.      public class Whiz {

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

3.                                      System.out.print("" + 1 + 2);

4.                                      System.out.print("" + (1 + 2));

5.                      }

6.      }


Options are :

  • 33
  • 312
  • 1212
  • 123 (Correct)
  • Compilation fails

Answer :123

Which of the following will result false?   


Options are :

  • true ^ false | true
  • (true ^ false) | true
  • (true ^ false | true)
  • true ^ (false | true) (Correct)
  • None of the above

Answer :true ^ (false | true)

Consider this program code -

1.            public class Whiz{

2.               

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

4.                            String s1 = "Rekha";

5.                            //insert here

6.               

7.                            System.out.print(s1.equals(s2)+" ");

8.                            System.out.print(s1 == s2);

9.                                           

10.             }

11.        }                                                                                                            

 Which of the following statement is true?

                              I.      String s2 = "Rekha";

                              II.     String s2 = new String("Rekha");


Options are :

  • Inserting the statement II at line 6, will produce the output as "true true" .
  • Inserting the statement I at line 6, will produce the output as "true false" .
  • Inserting the statement I at line 6, will produce the output as "false false" .
  • Inserting the statement II at line 6, will produce the output as "true false" . (Correct)
  • None of the above

Answer :Inserting the statement II at line 6, will produce the output as "true false" .

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

If "x.equals(y)" return true, which of the following is true?

    I.     "y.hashCode()" must be equal to "x.hashCode()"

   II.     Both "x" and "y" objects should have same field status.

  III.     "y.hashCode()" may be equal to "x.hashCode()"


Options are :

  • Only I. (Correct)
  • Only III.
  • Only I and II.
  • Only I and III.
  • All of the above

Answer :Only I.

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

1.          class A {

2.                          static void method() {

3.                                          System.out.print(" A B");

4.                          }

5.              }

6.                                         

7.              class B extends A {

8.                          protected static void method() {

9.                                          System.out.print(" C D");

10.                   }

11.       }         

12.                  

13.       class Program {

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

15.                                   A a = new B();

16.                                   a.method();

17.                   }

18.       }


Options are :

  • The output will be A B (Correct)
  • The output will be C D
  • The output will be A B C D
  • Run-time exception is thrown.
  • Compilation fails due to error at line 8.

Answer :The output will be A B

What will be the output of this program?

1.          class Animal {

2.              void run() {

3.                          System.out.print("Animal run");

4.              }

5.          }

6.           

7.          class Dog extends Animal {

8.           

9.                void sound() {

10.                   System.out.print("Bark");

11.         }

12.                  

13.          public void run() {

14.                   System.out.print(" Dog runs");

15.          }

16.    }

17.    class Program {

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

19.                                   Animal dog =  new Dog();

20.                                   dog.sound();

21.                                   dog.run();

22.                   }

23.   }


Options are :

  • Bark Dog runs
  • Bark Animal runs
  • Compilation fails due to an error at line 9.
  • Compilation fails due to an error at line 20. (Correct)
  • Compilation fails due to multiple errors.

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

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

Which of the following statement is true?   


Options are :

  • The up casting increases the capabilities of the object.
  • The up casting can't be occurred implicitly.
  • Casting subclass object to super class object is known as down casting.
  • With down casting, a ClassCastException is possible. (Correct)
  • None of the above.

Answer :With down casting, a ClassCastException is possible.

What will be the output of this program?

1.             class Person {

2.                          Person() {

3.                                          System.out.print("CP ");

4.                          }

5.                          static{ System.out.print("SP ");}

6.             }

7.              class Manager extends Person {

8.                         Manager(){

9.                                          System.out.print("CT ");

10.                   }

11.                   {System.out.print("IT ");}

12.       }

13.       class Program {

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

15.                                   Person p1 = new Manager();

16.                   }

17.       }         

 


Options are :

  • SP IT CP CT
  • CP CP IT SP
  • SP CP IT CT (Correct)
  • SP CP IT CT SP
  • Compilation fails

Answer :SP CP IT CT

Which of the following statement will override method() in class Sub?

1.        class Sup {

2.                 protected void method() {

3.                             System.out.print("Sup");

4.                 }

5.        }

6.        class Sub extends Sup {

7.                 //override method () here

8.        }         

 

 


Options are :

  • public final void method(){ } (Correct)
  • private void method() { }
  • void method() { }
  • public void method(int i) { }
  • protected int method() { return 0; }

Answer :public final void method(){ }

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

Consider below statements:


1. int x = 5____0;

2. int y = ____50;

3. int z = 50____;

4. float f = 123.76_86f;

5. double d = 1_2_3_4;


How many statements are legal?


Options are :

  • All 5 statements
  • Four statements only
  • Three statements only (Correct)
  • Two statements only
  • One statement only

Answer :Three statements only

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

Consider below code of Test.java file:


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


Options are :

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

Answer :true false

Given code of Test.java file:


Which of the block of codes can be used to replace /*INSERT*/ such that there is no compilation error?

Select ALL that apply.


Options are :

  • try { save(); log(); } catch(IOException | Exception ex) {}
  • try { save(); log(); } catch(Exception ex) {} (Correct)
  • try { save(); log(); } catch(IOException | SQLException ex) {} (Correct)
  • try { save(); log(); } catch(SQLException | IOException ex) {} (Correct)
  • try { save(); log(); } catch(SQLException | Exception ex) {}
  • try { save(); log(); } catch(Exception | RuntimeException ex) {}

Answer :try { save(); log(); } catch(Exception ex) {} try { save(); log(); } catch(IOException | SQLException ex) {} try { save(); log(); } catch(SQLException | IOException ex) {}

Consider below code of Test.java file:


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


Options are :

  • A
  • Runtime error
  • L (Correct)
  • K
  • S

Answer :L

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

Consider below codes of 3 java files:




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


Options are :

  • It compiles successfully and on execution prints 35.00 on to the console
  • It compiles successfully and on execution prints $35 on to the console
  • It compiles successfully and on execution prints $35.00 on to the console
  • Compilation error in Chair class
  • It compiles successfully and on execution prints 35.0 on to the console (Correct)
  • Compilation error in Test class
  • It compiles successfully and on execution prints 35 on to the console
  • It compiles successfully and on execution prints $35.0 on to the console

Answer :It compiles successfully and on execution prints 35.0 on to the console

Consider below code of main.java file:

Also consider below statements:

1. Code doesn't compile

2. Code compiles successfully

3. Only ONE will be printed to the console

4. Only TWO will be printed to the console

5. Both ONE and TWO will be printed to the console


How many of the above statements is/are true?


Options are :

  • Two statements (Correct)
  • Three statements
  • One statement

Answer :Two statements

Consider below code of AvoidThreats.java file:


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


Options are :

  • None of the other options
  • VIRUS VIRUS (Correct)
  • null null
  • VIRUS PHISHING
  • PHISHING PHISHING
  • null VIRUS

Answer :VIRUS VIRUS

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

Below is the code of Test.java file:

Below are the definitions of main method:

1.


2.


3.


4.


5.


How many definitions of main method can replace /* INSERT */ such that on executing Test class, "Java Rocks!" is printed on to the console?


Options are :

  • Only one definition
  • Only three definitions
  • Only two definitions (Correct)
  • All 5 definitions
  • Only four definitions

Answer :Only two definitions

Given code of Test.java file:


There is a compilation error in the code.

Which three modifications, done independently, print 1000 on to the console?


Options are :

  • Change Line n1 to private int var = 1000;
  • Change Line n5 to System.out.println(obj.getVar()); (Correct)
  • Delete the method getVar() from the Child class
  • Delete the Line n2 (Correct)
  • Change Line n3 to return var;
  • Change Line n4 to Parent obj = new Child(); (Correct)

Answer :Change Line n5 to System.out.println(obj.getVar()); Delete the Line n2 Change Line n4 to Parent obj = new Child();

Given code of Test.java file:


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


Options are :

  • END is printed and program terminates successfully
  • END is not printed and program terminates abruptly
  • END is printed and program terminates abruptly
  • Compilation error (Correct)

Answer :Compilation error

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

Consider below code of Test.java file:


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


Options are :

  • Line n2 causes compilation error
  • 10
  • Line n1 causes compilation error (Correct)
  • An exception is thrown at runtime
  • 100

Answer :Line n1 causes compilation error

Consider below codes of 3 java files:




Which of the following needs to be done so that there is no compilation error?


Options are :

  • No need for any modifications, code compiles as is
  • Replace /*INSERT*/ with below code: public default double profit() { return 50.0; }
  • Replace /*INSERT*/ with below code: public double profit() { return Profitable2.super.profit(); } (Correct)
  • Replace /*INSERT*/ with below code: protected double profit() { return 50.0; }
  • Replace /*INSERT*/ with below code: double profit() { return 50.0; }
  • Replace /*INSERT*/ with below code: public double profit() { return Profitable1.profit(); }

Answer :Replace /*INSERT*/ with below code: public double profit() { return Profitable2.super.profit(); }

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions