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

What will be the output of this program?

1.             interface I{

2.                             public default void print(){

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

4.                             }

5.                                            

6.                             static void method(){

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

8.                             }

9.             }

10.                   

11.     

12.                   

13.    public class Whiz{

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

15.                                    I i =  new I(){};                  

16.                                    i.print();

17.                                    I.method();

18.                    }

19.    }

 

 


Options are :

  • IStatic (Correct)
  • An exception is thrown
  • Compilation fails due to an error at line 2
  • Compilation fails due to an error at line 15
  • Compilation fails due to multiple errors

Answer :IStatic

Which of the following is a valid long literal?


Options are :

  • 0x99ffCl (Correct)
  • 12
  • 12.8
  • 11.2l
  • None of the above.

Answer :0x99ffCl

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

Which operator is used by Java run time implementations to free the memory of an object when it is no longer needed?


Options are :

  • delete
  • free
  • new
  • clear
  • None of the above (Correct)

Answer :None of the above

What will be the output of this program?

1.      public class Whiz{

2.                     

3.                      static int x = 0b1;

4.                      static int y = 0xF;

5.                      static int z = 018;

6.       

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

8.                                     

9.                                      System.out.println(x+z+y);

10.                 }

11.  

12.     }

 


Options are :

  • 31
  • 32
  • 34
  • Compilation fails due to an error on line 4.
  • Compilation fails due to an error at line 5 (Correct)

Answer :Compilation fails due to an error at line 5

What will be the output of this program?

1.      class Whiz {

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

3.                      int array[] = {1,2,3};

4.                      double dbls[] = array;

5.                      double sum = 0;

6.                      for (int i = 0; i < array.length; ++i)

7.                                      sum += dbls[i];

8.                      System.out.println(sum);

9.              }

10. }

 


Options are :

  • 6
  • 6.0
  • 3.0
  • An exception is thrown
  • Compilation fails (Correct)

Answer :Compilation fails

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

How many objects are eligible for GC when line 10 is reached?

1.      class Wrap {

2.               Double d = 10.0;

3.               int x = 10;

4.               int [ ] s = new int[10];

5.      }

6.      public class Whiz {

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

8.                        Wrap w =new Wrap();

9.                        w = null;

10.          }

11. }

 


Options are :

  • 1
  • 2
  • 3 (Correct)
  • 4
  • Compilation fails

Answer :3

Which of the following will compile successfully when inserted at line 4?

1.      class Program{

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

3.                                      Print p = new Print();

4.                                      //insert here

5.                      }

6.      }

7.       

8.      class Print{

9.                      static void p2(int i){

10.                                 System.out.print(i*2);

11.                 }

12.                 void print(int i){

13.                                 System.out.print(i);

14.                 }

15. }

 


Options are :

  • Print.p2();
  • p.p2(6); (Correct)
  • System.out.print(p.print(6));
  • Print.print(3);
  • None of the above

Answer :p.p2(6);

Which of the following will print true?

Double d = 10.0;

int i = 10;

Integer wi = 10;


Options are :

  • System.out.print((wi == d));
  • System.out.print(d == i); (Correct)
  • System.out.print(d.equals(i));
  • System.out.print(d.equals(wi));
  • System.out.print(wi.equals(d));

Answer :System.out.print(d == i);

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

Which of the following can be used to get the maximum possible value for an integer?


Options are :

  • Integer.max;
  • Integer.MAX_VALUE; (Correct)
  • new Integer().max();
  • new Integer().MAX;
  • None of these

Answer : Integer.MAX_VALUE;

What will be the output of this program?

1.          class Whiz {

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

3.                             Double d = 10;

4.                             int i = 10;

5.                             Integer wi = 10;

6.                             System.out.print((wi == i) + " ");

7.                             System.out.print(d == i);

8.                    }

9.        }

 

 


Options are :

  • true false
  • false false
  • true true
  • Compilation fails due to an error at line 3 (Correct)
  • Compilation fails due to an error at line 7

Answer :Compilation fails due to an error at line 3

What will be the output of this program?

1.          class Whiz {

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

3.                             char a = 'C';

4.                             a++;

5.                             System.out.print(a);

6.                    } 

7.          }                                                                                                                                             



Options are :

  • C
  • D (Correct)
  • 68
  • An Exception is thrown
  • Compilation fails due to an error at line 5

Answer :D

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

What will be the output of this program?

1.          class Whiz {

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

3.                             Double d = 0.0;                

4.                             System.out.print(d.BYTES);

5.                             System.out.print(d.SIZE);           

6.                    } 

7.          }

 

 


Options are :

  • 00
  • 80
  • 88
  • 864 (Correct)
  • Compilation fails due to an error at line 5

Answer :864

What will be the output of this program?

1.             class Whiz{

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

3.                                  A ab = new B();

4.                                  ab.print();

5.                                  ab.print("C");

6.                             }

7.             }

8.              

9.             class A{

10.                    public void print(){

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

12.                    }

13.    }

14.     

15.    class B extends A{

16.                    public void print(String s){

17.                                    System.out.print(s);

18.                    }

19.    }                             

 

 


Options are :

  • AA
  • CC
  • AC
  • An exception is thrown
  • Compilation fails (Correct)

Answer :Compilation fails

You are asked to create a method which should satisfy the following requirements.

The method should be a non-abstract method. It should take no parameters. It shouldn't return anything. Name of the method should be "print". And it should be an instance Method. This method is used in an interface.

Which is the correct method signature?


Options are :

  • void print()
  • static void print()
  • default void print() (Correct)
  • public void print()
  • public abstract print()

Answer :default void print()

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

Which of the following is not a part of the method signature?

 


Options are :

  • Return type (Correct)
  • Method name
  • Type of parameters
  • Number of parameters
  • Order of the parameters

Answer :Return type

What will be the output of this program?

1.             public class Program{

2.                             int x = 10;

3.                            

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

5.                                             int y = 12;

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

7.                                             int x = 11;

8.                             }             

9.             }                             

 


Options are :

  • 21
  • 22
  • 23
  • Compilation fails due to an error at line 6 (Correct)
  • Compilation fails due to multiple errors

Answer :Compilation fails due to an error at line 6

What is the output while compiling class B?

1.             package one;

2.              

3.             class A{

4.                  protected int j = 12;

5.             }

6.            package two;

7.              

8.             import one.*;

9.              

10.       class B extends A{

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

12.                        A a = new A();

13.               }

14.       }

 

 


Options are :

  • Compilation succeeds
  • Compilation fails due to an error at line 10
  • Compilation fails due to an error at line 12
  • Compilation fails due to multiple errors (Correct)

Answer :Compilation fails due to multiple errors

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

Which of the following declarations are valid ?


Options are :

  • float f = 10.5;
  • double d = 10.5; (Correct)
  • int i = 10.5;
  • float f =(float) 10.5; (Correct)

Answer :double d = 10.5; float f =(float) 10.5;

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

Consider the code:

What is the result?


Options are :

  • An exception is thrown at runtime.
  • Compilation Fails.
  • ab
  • 195 (Correct)

Answer :195

Consider the code:

What is the result?


Options are :

  • 20
  • The Compilation Fails. (Correct)
  • 20.0
  • An exception is thrown at runtime.

Answer :The Compilation Fails.

Consider the code:

and the command invocation

java Test Core Java Advanced Java

What is the result?


Options are :

  • TestCoreJavaAdvancedJava
  • An exception is thrown at runtime.
  • CoreJava
  • CoreJavaAdvancedJava (Correct)

Answer :CoreJavaAdvancedJava

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

The variables which are declared inside a method are considered as


Options are :

  • local variables (Correct)
  • instance variables
  • static variables
  • class variables

Answer :local variables

Consider the following code:

What is the result?


Options are :

  • 12 21 (Correct)
  • 12 22
  • 11 21
  • Compilation Fails as we are accessing static variable from instance method.

Answer :12 21

Consider the following statements :

S1: Once we compiled java source file, it can run on any platform where JRE is available. This feature is called Write Once and Run Anywhere(WORA)

S2: Java is platform independent where as JVM is platform dependent.

Which of the above statements are TRUE?


Options are :

  • Only S2
  • Both S1 and S2 (Correct)
  • Only S1
  • None S1 and S2

Answer :Both S1 and S2

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

Consider the following code:

and the command invocation

java Test Core Java Advanced Java

What is the result?


Options are :

  • Test
  • An exception is thrown at runtime.
  • Core Java
  • Core (Correct)

Answer :Core

Which of the following are valid array declarations?


Options are :

  • int[][] x = new int[2][2]; (Correct)
  • int[][] x = new int[][2];
  • int[][] x = new int[][];
  • int[][] x = new int[2][]; (Correct)

Answer :int[][] x = new int[2][2]; int[][] x = new int[2][];

Consider the following statements :

S1: For instance variables JVM will provide default values.

S2: For static variables JVM will provide default values.

S3: For local variables JVM will provide default values.

Which of the following are True?


Options are :

  • All S1,S2 and S3.
  • Only S2 and S3.
  • Only S1 and S3.
  • Only S1 and S2. (Correct)

Answer :Only S1 and S2.

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

Which of the following are TRUE ?


Options are :

  • For double type variables, the default value is 0.0. (Correct)
  • For char type variables, the default value is null.
  • For String type variables, the default value is null. (Correct)
  • For int type variables, the default value is 0. (Correct)
  • For boolean type variables, the default value is true.

Answer :For double type variables, the default value is 0.0. For String type variables, the default value is null. For int type variables, the default value is 0.

Consider the code:

What is the result?


Options are :

  • 30...30
  • The compilation fails. (Correct)
  • 10...20
  • 40...20

Answer :The compilation fails.

Consider the code:

What is the result ?


Options are :

  • Compilation Fails.
  • NewDemo (Correct)
  • Demo
  • An exception is thrown at runtime.

Answer :NewDemo

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

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions