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

What will be the output of this program?

1.      class Access{     

2.               native int AccessCode;

3.               transient Integer AccessCode2 = 1000;

4.               Access(int i){

5.                      AccessCode = i;

6.               }

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

8.                      System.out.print(new Access(1020).AccessCode);

9.                }             

10.    }

 

 


Options are :

  • 0
  • 1020
  • Compilation fails due to an error at line 2. (Correct)
  • Compilation fails due to an error at line 3.

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

What will be the output of this program?

1.      class Whiz{

2.                      int i = 10;

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

4.                                      int i;

5.                                      if(new Whiz().go(10))   i = 5;

6.                                                      System.out.print(i);

7.                      }

8.                      boolean go(int y){

9.                                      if(y>5) return true;

10.                                 else return false;

11.                 }

12.     }

 

 

 


Options are :

  • 5
  • 10
  • An exception will be thrown at runtime.
  • Compilation fails due to an error at line 4.
  • Compilation fails due to an error at line 6. (Correct)

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

What will be the output of this program?

1.      class Person{

2.                      int age;

3.                      String name;

4.                      public void read(){

5.                                      System.out.print("Person is reading ");

6.                      }

7.                      private void other(){}

8.       }

9.      class Livera extends Person{

10.                 Livera(String s ,int i){

11.                                 age = i;

12.               name = s;

13.                 }

14.                 public void read(){

15.                                 System.out.print(name +" is reading ");

16.                 }             

17.                  public void other()throws Exception{} 

18.  }

19. public class Whiz{

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

21.                                 Livera s = new Livera("Livera" , 22);

22.                                 Person p =s;

23.                                 s.read();

24.                                 p.read();

25.                 }

26.   }

 

 


Options are :

  • Livera is reading Livera is reading (Correct)
  • Livera is reading Person is reading
  • An exception will be thrown at runtime.
  • Compilation fails due to an error at line 22
  • None of the above.

Answer :Livera is reading Livera is reading

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

What will be the output of this program?

1.      class SuperClass{

2.                      public void method(){

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

4.                      }

5.      }

6.      final class Sub extends SuperClass{

7.                      public void method(){

8.                                      System.out.print("SubClass");

9.                      }

10. }

11. public class SubSub extends Sub{

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

13.                                 ((SuperClass)new SubSub()).method();

14.                 }

15.                 public void method(){

16.                                 System.out.print("SubsubClass");

17.                 }

18. }

 

 


Options are :

  • The output will produce SubsubClass
  • The output will produce SubClass
  • The output will produce SuperClass
  • An exception will be thrown at runtime.
  • Compilation fails. (Correct)

Answer :Compilation fails.

What will be the output of this program?

1.      class Whiz{

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

3.                       System.out.print(new Whiz().check(10));

4.              }

5.              boolean check(short x){

6.                     if(x<10) return true;

7.                     else return false;

8.              }

9.      }

 

 


Options are :

  • false.
  • true
  • An exception is thrown at runtime
  • Compilation fails due to an error at line 3 (Correct)
  • Compilation fails due to multiple errors

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.                        Double d = 8.08;

4.                        System.out.print(d instanceof Object);

5.               }

6.      }

 

 


Options are :

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

Answer :true

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

What will be the output of this program?

1.      class Whiz{

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

3.                                      double d = new Divider().divide(30,3);

4.                                      System.out.print(d);

5.                      }

6.      }

7.       

8.      class Divider{

9.                      double divide(int i, int j){

10.                                 return i/j;

11.                 }

12.    }

 

 


Options are :

  • 10.0 (Correct)
  • 10
  • 0.0
  • Compilation fails due to an error at line 3.
  • An exception is thrown.

Answer :10.0

Which of the following is/are true?

1.         The variables declared inside a method are called local variable.

2.         The local variables are initialized to its default value.

3.         The variable "s" in the declaration "short s = 10" should be an instance variable.

 

 


Options are :

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

Answer :Only I.

Which of the following set 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'

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

What will be the output of this program?

1.      class Whiz{

2.      int x = 012;

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

4.                        Whiz pr = new Whiz();

5.                        pr.go(20);

6.             }

7.             void go(final int i){

8.                    System.out.print(i/x);

9.             }

10.    }

 

 


Options are :

  • 1
  • 2 (Correct)
  • 0
  • Compilation fails due to an error at line 2.
  • Compilation fails due to an error at line 7.

Answer :2

What will be the output of this program?

1.      class MainClass{

2.                      MainClass(){    System.out.print("MainClass ");                                }             

3.      }

4.      class SubClass extends MainClass{

5.                      {System.out.print("I ");}

6.                      static{System.out.print("S ");}

7.                      SubClass(int i){

8.                                      this();

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

10.                 }

11.                                                                

12.                 SubClass(){

13.                                 super();

14.                                 System.out.print("SubClass ");

15.                 }

16.  }

17. public class SubSubClass extends SubClass{

18.                 SubSubClass(String s){

19.                                 super();

20.                                 System.out.print("SubSubClass ");

21.                 }

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

23.                                 new SubSubClass("ABC");

24.                 }

25.  }

 

 


Options are :

  • MainClass S I SubClass SubSubClass
  • S MainClass I SubClass SubSubClass (Correct)
  • S MainClass I SubClass SubClass SubSubClass
  • SubSubClass SubClass S I MainClass
  • Compilation fails

Answer :S MainClass I SubClass SubSubClass

Which of the following statement is invalid?   


Options are :

  • Overloaded methods may change the argument list. (Correct)
  • Overridden methods should not change the argument list.
  • Overloaded methods must change the argument list.
  • Overloaded methods can change return type.
  • In Overridden methods, object type determines which method is selected.

Answer :Overloaded methods may change the argument list.

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

What will be the output of this program?

1.       

1.         class Person{

2.                   Person() {

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

4.                   }

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

6.          }

7.              

8.          class Student extends Person {

9.                     Student() {

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

11.                 }

12.      }

13.     

14.     class Teacher extends Person {

15.                Teacher() {

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

17.                 }

18.                 private Teacher(String s){

19.                         System.out.print("OCT ");

20.                 }

21.      }

22.     

23.      class Whiz {

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

25.                         Person p1 = new Teacher("name");

26.                         Student s1 = new Student();

27.                }

28.       } 

 

 

 


Options are :

  • SP OCT CP SP CS
  • SP CP IT OCT CP CS
  • SP CP OCT CP CS
  • SP CP OCT CT SP CP CS
  • Compilation fails. (Correct)

Answer :Compilation fails.

Which of the following is the correct method signature of overloaded version of this method?

public void method() { / *codes */}


Options are :

  • public int method()
  • private void method()
  • private int method(String s) (Correct)
  • public String method()
  • None of the above

Answer :private int method(String s)

What will be the output of this program?

1.       public class Whiz {

2.                            

3.                 int x = 10;

4.                 static int y = x;

5.                            

6.                 Whiz() {

7.                          y++;

8.                 }

9.                            

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

11.                     System.out.println(y + new Whiz().x);

12.                   

13.            }

14.     }

 

 


Options are :

  • 20
  • 21
  • 22
  • 23
  • Compilation fails. (Correct)

Answer :Compilation fails.

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

What will be the output of this program?

1.       class Whiz {

2.                  static {

3.                           x = 10;

4.                           y = 5;                      

5.                  }

6.        int x;

7.        final static int y ;

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

9.                  try {

10.                       Whiz pr =  new Whiz();

11.                       int c = pr.x/y;

12.                       System.out.print(c);

13.              } catch(ArithmeticException E) {

14.                       System.out.print("Arithmetic Exception");

15.                        }

16.             }

17.      }

 

 


Options are :

  • 0
  • 2
  • An Arithmetic Exception will be thrown.
  • Compilation fails due to an error an line 3. (Correct)
  • Compilation fails due to multiple errors.

Answer :Compilation fails due to an error an line 3.

What will be the output of this program?

1.      class Whiz{

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

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

4.                          String s = new String(sb.toCharArray());

5.                          s = s.concat(" 8");

6.                          System.out.print(s);

7.               }

8.      }

 

 


Options are :

  • OCAJP 8
  • OCAJP
  • 8
  • An Exception is thrown.
  • Compilation fails. (Correct)

Answer :Compilation fails.

What will be the output of this program?

1.      class Whiz{

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

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

4.                        sb.insert(sb.lastIndexOf("A"),true);

5.                        System.out.print(sb);

6.              }

7.      }

 

 


Options are :

  • aAtrueaA
  • aAatrueA (Correct)
  • atrueAaA
  • A StringIndexOutOfBoundsException is thrown
  • Compilation fails.

Answer :aAatrueA

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

What will be the output of this program?

1.      class Whiz{

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

3.                          String str = "1Z0-808";

4.                           str = str.replace("80", "81");

5.                           str = str.substring(str.indexOf("80"), str.lastIndexOf("80"));

6.                           System.out.print(str);

7.                }

8.     

 

 


Options are :

  • 08
  • 80
  • No output will be printed.
  • An Exception is thrown. (Correct)
  • Compilation fails.

Answer :An Exception is thrown.

Which of the following can be used to get the number of characters in a string object?   


Options are :

  • size()
  • capacity
  • length
  • length() (Correct)
  • None of the above

Answer :length()

Which of the following(s) is/are valid array initialization/s?   


Options are :

  • int [ ] array [ ] = new int [ ][ ];
  • int [ ][ ] two = new int [ ][5];
  • int #one [ ] = new int [5];
  • int [3][ ] three = new int [ ][ ];
  • int [ ] one = new int [6]; (Correct)

Answer :int [ ] one = new int [6];

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

What will be the output of this program?

1.      class Whiz {

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

3.                           int a[ ] [] = { {1,2,4} , {5,2,1},{0,43,2}};

4.                           int b[ ] = a[2];

5.                          System.out.print(b[1]);

6.                 }

7.      }             

 

 


Options are :

  • 4
  • 5
  • 43 (Correct)
  • 2
  • Compilation fails due to an error at line 4

Answer :43

What will be the output of this program code?

1.      class Whiz {

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
  • false true
  • true true (Correct)
  • Compilation fails

Answer :true true

What will be the output of this program code?

1.      class Whiz {

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

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

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

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

6.                                      System.out.print(a[1][2]);

7.                      }

8.      }             

 

 


Options are :

  • 2
  • 3 (Correct)
  • Exception will be thrown at runtime.
  • Compilation fails due to an error at line 3.
  • Compilation fails due to an error at line 4.

Answer :3

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

What will be the output of this program code?

1.             import java.util.Arrays;

2.              

3.             public class Whiz {

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

5.                               int [ ][ ] ints = new int[2][];

6.              

7.                               Arrays.sort(ints[1]);

8.                            

9.                              System.out.print(Arrays.toString(ints[1]));

10.                 }

11.        }             

 

 


Options are :

  • [0, 0, 0]
  • [null,null,null]
  • null
  • NullPointerException (Correct)
  • Compilation fails

Answer :NullPointerException

What will be the output of this program code?

1.             public class Whiz{

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

3.                             long size = 0xB;

4.                             int []ints = new int[size];

5.              

6.                             ints[5] = 10;

7.                            

8.                             System.out.print(ints[5] + 10);

9.                 }

10.    }             

 

 


Options are :

  • 20
  • 15
  • 10
  • A NullPointerException is thrown.
  • Compilation fails. (Correct)

Answer :Compilation fails.

What will be the output of this program code?

1.       import java.util.Arrays;
2.       public class Whiz{
3.                public static void main(String[] args) {
4.                         int[ ] ints = {3,6,1,4,0};
5.                         Arrays.sort(ints,0,4);
6.                                for(int i :  ints) {
7.                                       System.out.print(i);
8.                                }                             
9.                 }
10.      }             

 

 


Options are :

  • 01436
  • 01346
  • 13460 (Correct)
  • An Exception is thrown.
  • Compilation fails.

Answer :13460

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

Given the following set of classes:

class A extends Exception {}

class B extends A {}

class C extends B {}

 

What is the correct sequence of catch blocks for the following try block?

try {

 // codes

}

 


Options are :

  • Catch Exception, A, B and C
  • Catch Exception, C, B, and A
  • Catch A, B, C, and Exception
  • Catch C, B, A and Exception (Correct)
  • None of these

Answer :Catch C, B, A and Exception

Which of the following error/exception is typically thrown by JVM?   


Options are :

  • IllegalStateException
  • AssertionError
  • StackOverflowError (Correct)
  • ArrayIndexOutOfBoundsException (Correct)
  • All of the above.

Answer :StackOverflowError ArrayIndexOutOfBoundsException

What will be the output of this program code?

1.      class Whiz {

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

3.                         try {

4.                                  System.out.print("try Started ");

5.                                   throw new Exception();

6.                          } catch(Exception e) {       

7.                                   throw e;

8.                          } finally {

9.                                   System.out.print("Finally Completed");

10.                     }

11.          }

12. }

 

 


Options are :

  • Compilation fails.
  • try Started Finally Completed followed by an exception . (Correct)
  • try Started followed by an exception Finally Completed .
  • An exception is thrown at runtime without printing try Started or Finally Completed.

Answer :try Started Finally Completed followed by an exception .

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

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions