Oracle Certified Associate
Practice Set 02

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

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

Questions from 15 to 28

Question 15.

Select all correct answers.
What is the result?

01. interface HasASCII {String getASCII();}
02. enum ASCII implements HasASCII {
03.    code1 {
04.       public String getASCII() {return "FF0000";}
05.    }, code2{
06.       public String getASCII() {return "00FF00";}
07.    }, code3{
08.       public String getASCII() {return "0000FF";}
09.    }
10. }
11. class CodingASCII {
12.    static void main(String[] c) {}
13.       final void convertion (ASCII c) {
14.          System.out.print("Converting: "+c.getASCII());
15.       }
16.    }
17.
18.     final public class Demo extends CodingASCII {
19.
20.    final public static void main(String[] code) {
21.          new CodingASCII().convertion(ASCII.code1);
22.     }
23. } 


Option a: Converting: 00FF00
Option b: Converting: FF0000
Option c: Converting: 0000FF
Option d: Three lines of code do not compile.
Option e: The code compiles but prints an exception at runtime. 


Option b: Converting: FF0000

Question 16.

Select the most appropriate answer.
What is the output of the following application? Assume the file system is available and able to be written to and read from.

package boat;
import java.io.*; public class Cafe {
   private int numCustomers = 1;
   private transient String schedule = "NONE";
    {numCustomers = 2;}
    public Cafe() {
       this.numCustomers = 3;
       this.schedule = "Slot MidDay";
    }
    public static void main(String... customer) throws Exception {
       try (ObjectOutputStream o = new ObjectOutputStream(
       new FileOutputStream("booth.txt"))) {
       Cafe c = new Cafe();
       c.numCustomers = 4;
      c.schedule = "Slot";
      o.writeObject(c);
   }
   try (ObjectInputStream i = new ObjectInputStream(
      new FileInputStream("booth.txt"))) {
         Cafe c = i.readObject();
          System.out.print(c.numCustomers +","+c.schedule);
      }
   }
}


Option a: 2, NONE
Option b: 3, null
Option c: 4, Casino
Option d: 4, null
Option e: The class does not compile.
Option f: The class compiles but throws an exception at runtime. 


Option e: The class does not compile. 

Question 17.

Select the most appropriate answer.
What is the result of compiling and running this code:

enum Fries { kids, small, medium, large}
public class McDonald {
   public static void main (String args []) {
      Buy f =new Buy ();
      f.size = Fries.medium;
      System.out.println(f.size);
   }
}
class Buy {
    Fries size;
}


Option a: Produce a compile time error ‘class Test is public, should be declared in a file named Test.java’
Option b: Produce a compile time error ‘modifier private not allowed here’
Option c: Print out “medium”
Option d: The program will not compile.
Option e: The program generates a runtime exception.
Option f: Program does not terminate. 


Option c: Print out “medium”

Question 18.

Select all correct answers.
which of the following statements are true, with respect to the following?

public class Bike {.........................}
public class kawasaki extends Bike {.........................}
public class ninja extends kawasaki{.........................}


Option a: ninja inherits both kawasaki and Bike.
Option b: Bike is a subclass of ninja
Option c: kawasaki is derived form ninja.
Option d: Bike is a superclass of kawasaki
Option e: Bike is a subtype of both kawasaki and ninja.
Option f: Bike is derived form kawasaki.
Option g: ninja is derived form Bike.


Option a: ninja inherits both kawasaki and Bike.
Option d: Bike is a superclass of kawasaki
Option g: ninja is derived form Bike.

Question 19.

Select the most appropriate answer.
What is the result of compiling and running this code:
Given:

class Player_7 {
   public String Test() {
      String Player = "Cristiano Ronaldo";
      return Player;
   }
}
public class Football  {
   public static void main (String args []) {
    Player_7 p =new Player_7();
      String Player = p.Test();
      System.out.println(Player);
   }
}


Option a: Prints “Cristiano Ronaldo”.
Option b: Generates a runtime error.
Option c: Does nothing.
Option d: Generates a compile time error.


Option h: Below Range

Question 20.

Select the most appropriate answer.
What is the result of compiling and running this code:

1. package demoPackage;
2. public class Test_1 {
3.    // TODO Auto-generated constructor stub
4.    String name;
5.    Test_1(String name) {
6.       this.name = name;
7.    }
8.    Test_1() {
9.       this(giveRandomName());
10.   }
11.     static String giveRandomName() {
12.        int x = (int) (Math.random()*4);
13.        String name = new String[] {"Ronaldo ", "Chris ", "Happy ", "Joy "}[x];
14.       return name;
15.    }
16. }
17.
18. public class Demo {
19.      public static void main (String args []) {
20.           Test_1 a =new Test_1();
21.            System.out.print(a.name);
22.           Test_1 b =new Test_1("Malik");
23.           System.out.println(b.name);
24.     }
25. }



Option a: Always Prints “Ronaldo Malik”.
Option b: Generates a runtime error.
Option c: Will print any one of these “Ronaldo Malik”, “Chris Malik”, “Happy Malik” or “Joy Malik”.
Option d: Generates a compile time error.
Option e: Does nothing.


Option d: Generates a compile time error.

Question 21.

Select the most appropriate answer.
What is the result of compiling and running this code:
Given:

class Demo {
   int x = 20;
   public static void main (String args []) {
      int y = 10;
      System.out.print("Number y is "+ y + " & ");
      System.out.print("Number x is "+ x);
   }
}


Option a: Generates a compile time error.
Option b: Generates a runtime error.
Option c: Prints ‘Number y is 10 & Number x is 20’.
Option d: Does nothing.


Option a: Generates a compile time error. 

Question 22.

Type correct answers.
Given:

package demoPackage;
class R {
   R() {
      System.out.println("My name is R.");
   }
}
class S {
   S() {
      System.out.println("My name is S.");
   }
}
class X {
   X() {
      System.out.println("My name is X");
   }
}
class B {
   B() {
      System.out.println("My name is B.");
   }
}
public class Demo {
   public static void main (String args []) {
       // insert code fragment here.
   }
}


Output:
My name is X.

Code Fragment:
S, R, new,  X, B, (, ),;
Type the proper order of the code fragments that must be inserted to get the output shown, after compiling and running this code:


new X();

Question 23.

Select the most appropriate answer.
What is the result of compiling and running this code:
Given:

package demoPackage;

public class Demo {
   String x = "Hi";
   public static void main(String args[]) {
      final Demo b1 = new Demo();
      Demo b2 = new Demo();
      Demo b3 = BuzzSwitch(b2);
      System.out.println((b1 == b3) + " " + (b1.x == b3.x));
   }

   Demo BuzzSwitch(Demo x) {
      final Demo z = x;
      z.x = "Good Day";
      return z;
   }
}


Option a: Prints true true.
Option b: Prints false true.
Option c: Prints true false.
Option d: Prints false false.
Option e: Generates a compile time error.
Option f: Generates a runtime error.
Option g: Does nothing.


Option e: Generates a compile time error.

Question 24.

Select the most appropriate answer.
What is the result this code snippet:
Given:

public class Demo {
   static int x = 35;
   static char y = 'x';
   public static void main (String args []) {
      if (x == y){
          System.out.println("x");
      } else {
          System.out.println("!x");
      }
  }
}


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


Option b: Prints “!x”

Question 25.

Select the most appropriate answer.
What is the result when 3 of these code fragments are inserted independently at line 4:
Given:

1. package demoPackage;
2. import java.io.IOException;
3. public class Demo {
4.    // insert code here
5.     int x = 7;
6.     System.out.println(7/x);
7.   }
8. }


Code Fragment:
public static void main (String args []) throws IOException {
public static void main (String args []) throws Exception {
public static void main (String args []) throws RuntimeException {

Option a: All 3 code fragments will compile and execute and throw an exception.
Option b: All 3 code fragments will compile and execute without throwing an exception.
Option c: Some but not all, will compile and execute without throwing an exception.
Option d: Some but not all, will compile and execute and throw an exception.
Option e: Does nothing. 


Option b: All 3 code fragments will compile and execute without throwing an exception.

Question 26.

Select all correct answers.
Which of the following are true with respect members in Java?



Option a: Members cannot use all four access levels: public, protected, default, and private.
Option b: If a class cannot be accessed, its members can be accessed.
Option c: public members can be accessed by all other classes, even in other packages.
Option d: If a superclass member is public, the subclass inherits it—regardless of package. 


Option c: public members can be accessed by all other classes, even in other packages.
Option d: If a superclass member is public, the subclass inherits it—regardless of package. 

Question 27.

Select all correct answers.
What is the output?

package demoPackage;

import java.util.*;

public class Demo {
   private int count = 0;

   protected Object[][] getObject() {
      return new Object[][] { { "count", count++ } };
   }

   public static void main(String[] args) {
      ResourceBundle rb = ResourceBundle.getBundle("count");
      System.out.println(rb.getObject("count") + " " + rb.getObject("count"));
   }

}


Option a: 0 0
Option b: 0 1
Option c: The code does not compile.
Option d: The code compiles but throws an exception at runtime.


Option c: The code does not compile.

Question 28.

Select all correct answers.
Which three statements are true?


Option a: The synchronized modifier applies only to methods and code blocks.
Option b: synchronized methods can have any access control and can also be marked final.
Option c: The native modifier doesn’t apply to methods.
Option d: The strictfp modifier doesn’t apply to classes and methods.


Option a: The synchronized modifier applies only to methods and code blocks.
Option b: synchronized methods can have any access control and can also be marked final.

 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.

Mobirise Website Builder
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 Code Creator