Oracle Certified Associate
Practice Set 01

Java SE 8 Programmer I exam (1Z0 | 808) Certification

Duration 120 minutes,
Format: Multiple Choice
Number of Questions: 56
Passing Score: 65%

Questions from 43 to 56

Question 43.

Select the most appropriate answer.
Given:

import java.util.*;
public class ArrayTest {
    public static void main(String[] args) {
           List fishes = new ArrayList();
           fishes.add("catfish");
           fishes.add(1, "goldfish");
           fishes.add(0, "clownfish");
           fishes.add(1, "swordfish");
           System.out.println(fishes);
     }
}


What is the output?

Option a: [clownfish, swordfish, catfish, goldfish]
Option b: [clownfish, swordfish]
Option c: Generates a runtime error.
Option d: Generates a compile time error. 


Option a: [clownfish, swordfish, catfish, goldfish]

Question 44.

Select the most appropriate answer.
Given:

public class Demo {
   public static void main(String[] args) {
         InitializationExample init = new InitializationExample();
         init.sum();
   }
}
class InitializationExample {
    private String name = "Integer";
       { System.out.println(name); }
       private static int COUNT = 0;
       static { System.out.println(COUNT); }
       static { COUNT += 10; System.out.println(COUNT); }
    public InitializationExample() {
            System.out.println("constructor");
    }
    private void sum() {
            COUNT++;
            System.out.println(COUNT);
    }
}



What is the output?

Option a: Prints output 0
10
Integer
constructor
Option b: Generates a runtime error.
Option c: Generates a compile time error.
Option d: Does nothing.


Option c: Generates a compile time error. 

Question 45.

Select all correct answers.
What is the output of the following code?

01. package demoPackage;
02. class Mammal {
03.  public Mammal(int age) {
04.        System.out.print("Mammal " + age);
05.   }
06. }
07. public class Demo extends Mammal {
08.   public Demo() {
09.        System.out.print("Elephant");
10.    }
11.    public static void main(String[] args) {
12.        new Mammal(5);
13.    }
14. }


Option a: Elephant
Option b: Mammal
Option c: ElephantMammal
Option d: The code will not compile because of line 8.
Option e: The code will not compile because of line 11.


Option d: The code will not compile because of line 8. 

Question 46

Select the most appropriate answer.

package demoPackage;

import java.io.*;
class OutOfTuneException extends Exception {
      OutOfTuneException(String message) { super(message); }
}
public class Demo {
       public void play() throws OutOfTuneException, FileNotFoundException {
       throw new OutOfTuneException("Sour note!");
}
public static void main(String... keys) {
        final Demo piano = new Demo();
        try {
              piano.play();
        } catch (Exception e) {
              System.out.println(e);
        } finally {
              System.out.println("Song finished!");
        }
    }


Which of the following could be a possible output?

Option a: Song finished!
Option b: An exception is printed: Sour note! 
Option c: Both of the above.
Option d: None of the above. 


Option c: Both of the above.

Question 47.

Select the most appropriate answer.
Given:

// file Animal.java
public class Animal {
   public int length = 2;
}
// file Jellyfish.java
public class Tiger extends Animal {
   public int length = 5;
   public static void main(String[] args) {
         Tiger tiger = new Tiger();
         Animal animal = new Tiger();
         System.out.print(tiger.length);
         System.out.print(animal.length);
    }
}


What is the result?

Option a: Prints output: 52
Option b: Generates a run time error.
Option c: Generates a compile time error.
Option d: Prints output: 25
Option e: Does nothing.


Option a: Prints output: 52 

Question 48.

Select the most appropriate answer.
In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected:

1. public class demo {
2.    public static void main (String args []) {
3.       Employee e = new Employee("Bob", 48);
4.       e.calculatePay();
5.       System.out.println(e.printDetails());
6.       e = null;
7.       e = new Employee("Denise", 36);
7.       e.calculatePay();
9.       System.out.println(e.printDetails());
10.     }
11. }


Option a: Line 10
Option b: Line 11
Option c: Line 7
Option d: Line 8
Option e: Never


Option c: Line 7

Question 49.

Select the most appropriate answer.
Given:

3: do {
4:     int y = 1;
5:     System.out.print(y++ + " ");
6: } while(y <= 10);


What is the output?

Option a: 1 2 3 4 5 6 7 8 9
Option b: 1 2 3 4 5 6 7 8 9 10
Option c: 1 2 3 4 5 6 7 8 9 10 11
Option d: The code will not compile because of line 6.
Option e: The code contains an infinite loop and does not terminate.


Option d: The code will not compile because of line 6. 

Question 50.

Select the most appropriate answer.
Given:

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class BoolTest {
   public static void main(String[] args) {
      try {
         String email= "test.rmail@golf.com";
         Pattern p = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
         Matcher isEmailValid = p.matcher(email);
         boolean emailValid = isEmailValid.find();
         if (emailValid) {
            System.out.println("Okay");
          } else {
            System.out.println("Not Okay");
         }
     } catch (Exception e) {
         e.printStackTrace();
     }
  }
}


Option a: Prints: "Not Okay", in any case
Option b: Prints:"Okay", in any case
Option c: if the String email matches pattern, Prints: "Okay"
Option d: if the String email doesn’t match pattern, Prints: "Not Okay"
Option e: Generates a runtime error.
Option f: Generates a compile time error.


Option c: if the String email matches pattern, Prints: "Okay"

Question 51.

Select the most appropriate answer.
Given:

java.util.List values = new java.util.ArrayList();
    values.add("Lisa");
    values.add("Kevin");
    values.add("Roger");
for(String value : values) {
    System.out.print(value + ", ");
}


What is the output?

Option a: Lisa, Kevin, Roger,
Option b: Generates a runtime error.
Option c: Generates a compile time error.
Option d: Lisa, Roger, Kevin,
Option e: Kevin, Roger, Lisa,


Option a: Lisa, Kevin, Roger, 

Question 52.

Select the most appropriate answer.
Given:

public class BoolTest {
    public static void main(String[] args) {
         boolean x = false;
         boolean y = false;
         boolean z = x && y;
         z = x || y;
         z = !z;
         System.out.println(!z);
    }
}


What is the output?

Option a: true
Option b: false
Option c: Generates a compile time error.
Option d: Generates a runtime error.


Option b: false 

Question 53.

Select the most appropriate answer.
Given:

String x = "Java";
System.out.println(x.concat(" Rules!" ));


What is the result?

Option a: Prints: “Java”
Option b: Prints: “Java Rules!”
Option c: Generates a compile time error.
Option d: Generates a runtime error. 


Option b: Prints: “Java Rules!” 

Question 54.

Select the most appropriate answer.
Given:

class First {
     { System.out.println("1"); }
     public void Top() { System.out.println("2"); }
     public void Top(String s) { System.out.println("3"); }
}
class Second extends First {
     { System.out.println("4"); }
     public Second() { System.out.println("5"); }
     public Second(String s) { System.out.println("6"); }
}
public class Third extends Second {
     { System.out.println("7"); }
     public void Bottom()
     { System.out.println("8"); }
     public void Bottom(String s) { System.out.println("9"); }
     public static void main(String[] args) { new Third(); }
}


What is the result?

Option a: 147
Option b: 1457
Option c: 369
Option d: 123456
Option e: 215478
Option f: 456821
Option g: 561243


Option b: 1457 

Question 55.

Select all correct answers.
Given:

10. class One {
11.    public One foo() { return this; }
12. }
13. class Two extends One {
14.    public One foo() { return this; }
15. }
16. class Three extends Two {
17.     // insert method here
18. }


Which two methods, inserted individually, correctly complete the Three class?

Option a: public void foo() { }
Option b: public int foo() { return 3; }
Option c: public Two foo() { return this; }
Option d: public One foo() { return this; }
Option e: public Object foo() { return this; }


Option c: public Two foo() { return this; }
Option d: public One foo() { return this; }

Question 56.

Select the most appropriate answer.

package demoPackage;
public class Demo {
   static int dayOfWeek = 0;
   public static void main(String[] args) {
     switch (dayOfWeek) {
       default:
          System.out.print("Weekday ");
       case 0:
          System.out.print("Saturday ");
       case 6:
          System.out.print("Sunday ");
      }
   }
}


What is the output?

Option a: Prints: Weekday
Option b: Prints: Sunday
Option c: Saturday Sunday
Option d: Generates a compile time error.
Option e: Generates a runtime error.


Option c: Saturday Sunday

 OCA Practice Tests (1Z0-808) app contributes in achieving Oracle Certified Associate (OCA) certification.

A total of 10 premium tests are provided.

The purpose of these practice tests is to assist Oracle Certified Associate (OCA) Aspirants to manage time better in the actual exam by asking them to answer questions similar to the ones that appear in exams. The test series helps you assess your preparation and identify your weakness well before the exam, thus assisting you prepare better.

Tests also include features like:
• 60 minutes, 15 minutes and 5 minutes remaining voice alerts.
• After completion, your performance is assessed and a report is generated.
• App also provides correct answers for the test after completion.

OCA Mobile Application
https://play.google.com/store/apps/details?id=in.co.vtree.ocamobiletab

Contact Details :---             
WhatsApp Number: +91 97422 63639              Telegram Number:  +91 97422 63639    
Mobile Number: +91 97422 63639              email id: contact@drdhajnana.com
Privacy Policy       Terms of Service
vtree.co.in

Made with ‌

HTML Editor