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

Which of the following options defines the correct structure of a Java class that compiles successfully? 


Options are :

  • class MyClass { int abc; String course = //this is a comment "eJava"; } (Correct)
  • class MyClass { import com.ejava.guru.*; }
  • package com.ejava.guru; package com.ejava.oracle; class MyClass { int age = /* 25 */ 74; }
  • All of the above

Answer :class MyClass { int abc; String course = //this is a comment "eJava"; }

Which one of the following is true for NullPointerException?


Options are :

  • This represents any exception which occurs during runtime
  • This exception occurs if you initialize a null value to the variable
  • When a method could not convert a string into a numeric format
  • This exception is raised when referring to the members of a null object. (Correct)

Answer :This exception is raised when referring to the members of a null object.

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

What is the output of the following?


Options are :

  • 090
  • 009
  • 9
  • 900 (Correct)

Answer :900

Why is the lambda expression important?


Options are :

  • It allows you to write code that has the execution put off for later time (Correct)
  • It allows you to convert a primitive to a reference type
  • It allows you to inherit from multiple classes when necessary
  • It allows to associate within classes

Answer :It allows you to write code that has the execution put off for later time

What is the output of the following code? 



Options are :

  • 23456789
  • 12345678
  • 310
  • 31
  • Runtime error (Correct)

Answer :Runtime error

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

What is the advantage of inheritance in java programming? (Select three)


Options are :

  • Code re-usability (Correct)
  • Need not to create a main method
  • Automatically holds objects from other classes
  • Class Extendibility (Correct)
  • Can save development time (Correct)

Answer :Code re-usability Class Extendibility Can save development time

What is the result of the following?


Options are :

  • [Natural History, Science]
  • [Natural History, Science, Art]
  • The code does not compile.
  • The code compiles but throws an exception at runtime. (Correct)

Answer :The code compiles but throws an exception at runtime.

What is the meaning of this Java Lambda expression?


Options are :

  • Given number n returns a boolean indicating if it is even
  • Given number n returns a boolean indicating if it is odd (Correct)
  • Given number n returns an even number
  • None of the above

Answer :Given number n returns a boolean indicating if it is odd

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

In which package does the LocalDate class exist?


Options are :

  • java.util.LocalDate
  • java.time.LocalDate (Correct)
  • java.time.lang
  • java.time.util.LocalDate

Answer :java.time.LocalDate

Which of the following is a correct conversion of string representation into integer value? 


Options are :

  • int n = Integer.parseInt("Hello");
  • int n = Integer.parseInt("45"); (Correct)
  • int n1 = Integer.parseInt(false);
  • None of these

Answer :int n = Integer.parseInt("45");

Fill in the blank: Checked exceptions are checked at ___________.


Options are :

  • the time of creating class
  • the time codding
  • compile time (Correct)
  • time of creating main method

Answer :compile time

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

Given the following statements,   

com.myjava is a package   

class Person is defined in package com.myjava   

class Course is defined in package com.myjava 

Which of the following options correctly import the classes Person and Course in the class MyClass? 


Options are :

  • import com.myjava; import com.myjava; public class MyClass { }
  • import com.myjava.Persoon.*; public class MyClass { }
  • import com.myjava.*; import com.myjava; public class MyClass { }
  • import com.myjava.Person; import com.myjava.Course; public class MyClass { } (Correct)

Answer :import com.myjava.Person; import com.myjava.Course; public class MyClass { }

What is the result of the following code? 


Options are :

  • It will reference address of the object b
  • It will print null value
  • It will print 0
  • The code has a compilation error (Correct)

Answer :The code has a compilation error

Assume that appropriate packages have been imported. What is the output of this code? 


Options are :

  • 2018-03-30T00:00 (Correct)
  • 2018-03-30
  • 2018-03-30 T12:00
  • Code will not compile

Answer :2018-03-30T00:00

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

What is the result for this code? 


Options are :

  • Code has a compilation error
  • 5.552
  • 5.0
  • 6.0 (Correct)

Answer :6.0

Given the following definitions of the class Book. Which one of the following statements is correct?


Options are :

  • METHOD1 and METHOD2 are correctly overloaded methods
  • METHOD2 and METHOD3 are correctly overloaded methods (Correct)
  • METHOD1, METHOD2 and METHOD3 are correctly overloaded methods
  • None of the above is correct

Answer :METHOD2 and METHOD3 are correctly overloaded methods

How many of the following lines of code compile?


Options are :

  • None
  • One
  • Two (Correct)
  • Three
  • Four
  • Five

Answer :Two

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

How many lines does the following code output?


Options are :

  • One (Correct)
  • Four
  • Five
  • The code does not compile.
  • The code compiles but throws an exception at runtime.

Answer :One

What is the result of the following when called as java counting.Binary?


Options are :

  • []
  • [0, 01, 1, 10] (Correct)
  • [0, 01, 10, 1]
  • [0, 1, 01, 10]
  • The code does not compile.
  • The code compiles but throws an exception at runtime.

Answer :[0, 01, 1, 10]

Which of the following substitutions will compile? (Choose two.)


Options are :

  • Change name to _name (Correct)
  • Change 10017 to _10017
  • Change 10017 to 10017_
  • Change 10017 to 10_0_17 (Correct)
  • Change int to _int

Answer :Change name to _name Change 10017 to 10_0_17

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

Which of the following is an arithmetic operator?   


Options are :

  • % (Correct)
  • =
  • !=
  • >
  • None of the above

Answer :%

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

Consider this given program code and choose the correct option.

1.       

1.        class Whiz {

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

3.                            final int i = 0;

4.                            final int j;

5.                            j=2;

6.                            int x= (int)(Math.random() * 3);

7.                

8.                            switch(x) {

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

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

11.                                 case j : System.out.print("C");

12.                       }

13.             }

14.      } 

Note: Math.random() * 3 will assign value 0,1 or 2 x.

 

 


Options are :

  • The output will be A
  • The output will be AB
  • The output will be B
  • The output will be BC
  • Compilation fails. (Correct)

Answer :Compilation fails.

Select the correct statement.   


Options are :

  • The only legal expression in an if statement is a Boolean expression (Correct)
  • Curly braces are essential for if blocks.
  • Switch statement can evaluate float data type.
  • The default keyword is must for switch statement.
  • double can be used as case constant.

Answer :The only legal expression in an if statement is a Boolean expression

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

I.     The overridden equals method of a class checks reference equality.

II.     The "==" invokes the equals method when used to check objects equality.

III.     The equals method is defined in the Object class.


Options are :

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

Answer :Only III

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

What will be the output of this program?

1.        class Whiz {

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

3.                           int x = 0, y =10;                                                                  

4.              

5.                           if (x++ > 1 && ++y >10)

6.                                   System.out.print(x + y);

7.                           if (++y > 10 || ++x >10)

8.                                    System.out.print(x + y);              

9.                  }

10.      }

 

 


Options are :

  • No output
  • 1112
  • 1012
  • 12 (Correct)
  • 13

Answer :12

What will be the output of this program?

1.         class Whiz {

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

3.                             int i = 3, j = 2;     

4.                             System.out.println(i-- + --j + ++i);

5.                     }

6.          }

 

 


Options are :

  • 8
  • 7 (Correct)
  • 6
  • 5
  • Compilation fails.

Answer :7

What will be the output of this program?

1.       class Animal {

2.                      public void eat()throws NullPointerException {

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

4.                      }

5.       }

6.       class Dog extends Animal {

7.                      void eat(String s)throws Exception{

8.                                      System.out.print("Dog eats "+ s);

9.                      }

10.  }

11.  

12.  public class Whiz {

13.                 public static void main (String [ ] args)throws Exception { 

14.                                 Animal a= new Dog();

15.                                 Dog d = (Dog)a;

16.                                 a.eat();

17.                                 d.eat("Meat");

18.                   }

19.  } 

 

 


Options are :

  • Animal eats Dog eats Meat (Correct)
  • Animal eats Animal eats
  • Compilation fails due to an error at line 15.
  • An exception will be thrown at runtime.
  • Compilation fails due to an error at line 17.

Answer :Animal eats Dog eats Meat

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

Which of following represents a correct interface?    


Options are :

  • interface I{ protected int x = 10; }
  • interface I{int x = 10; void print(){ } }
  • abstract interface I{ default void print(){ } } (Correct)
  • interface I{ default void print(); }
  • None of the above.

Answer :abstract interface I{ default void print(){ } }

Which of the following statement is true?   


Options are :

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

Answer :The down casting can't be occurred implicitly.

Given:

1.             class A { }

2.             class B extends A { }

3.             class Whiz {

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

5.                             A aa = new B();

6.                             A bb = new B();

7.                             A aaa = new A();

8.                       }

9.               }

Which of the following statement is true about the above code fragment?

I.            Object type of the variable "aa" is B.

II.           Reference type of the variable "bb" is B.

III.          Object type of the variable "aaa" is A.

 


Options are :

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

Answer :Only I and III.

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

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions