OCP Oracle Certified Professional Java SE 11 Developer Practice Tests. Jeanne Boyarsky

Читать онлайн.
Название OCP Oracle Certified Professional Java SE 11 Developer Practice Tests
Автор произведения Jeanne Boyarsky
Жанр Программы
Серия
Издательство Программы
Год выпуска 0
isbn 9781119696148



Скачать книгу

and their members using instance and static initialiser statements and constructorsUnderstand variable scopes, apply encapsulation and make objects immutableCreate and use subclasses and superclasses, including abstract classesUtilize polymorphism and casting to call methods, differentiate object type versus reference typeCreate and use interfaces, identify functional interfaces, and utilize private, static, and default methodsCreate and use enumerations

      1 What is the output of the following application?package dnd; final class Story { void recite(int chapter) throws Exception {} } public class Adventure extends Story { final void recite(final int chapter) { // g1 switch(chapter) { // g2 case 2: System.out.print(9); default: System.out.print(3); } } public static void main(String… u) { var bedtime = new Adventure(); bedtime.recite(2); } }3993The code does not compile because of line g1.The code does not compile because of line g2.None of the above.

      2 Which of the following lines of code are not permitted as the first line of a Java class file? (Choose two.)import widget.*;// Widget Managerint facilityNumber;package sprockets;/** Author: Cid **/void produce() {}

      3 Which of the following modifiers can be applied to an abstract method? (Choose two.)finalprivatepublicdefaultprotectedconcrete

      4 What is the result of compiling and executing the following class?1: public class ParkRanger { 2: int birds = 10; 3: public static void main(String[] data) { 4: var trees = 5; 5: System.out.print(trees+birds); 6: } 7: }It compiles and outputs 5.It compiles and outputs 15.It does not compile.It compiles but throws an exception at runtime.

      5 Fill in the blanks: The ___________________ access modifier allows access to everything the ___________________ access modifier does and more.package‐private, protectedprivate, package‐privateprivate, protectedprivate, publicpublic, privateNone of the above

      6 Which set of modifiers, when added to a default method within an interface, prevents it from being overridden by a class implementing the interface?constfinalstaticprivateprivate staticNone of the above

      7 Given the following application, fill in the missing values in the table starting from the top and going downward.package competition; public class Robot { static String weight = "A lot"; double ageMonths = 5, ageDays = 2; private static boolean success = true; public void main(String[] args) { final String retries = "1"; // P1 } }Variable TypeNumber of Variables Accessible at P1Class_____Instance_____Local_____2, 0, 12, 2, 11, 0, 10, 2, 1

      8 Given the following code, what values inserted, in order, into the blank lines allow the code to compile? (Choose two.)_______ agent; public _______ Banker { private static _______ getMaxWithdrawal() { return 10; } }package, new, intpackage, class, longimport, class, null//, class, intimport, interface, voidpackage, class, void

      9 Which of the following are correct? (Choose two.)public class Phone { private int size; // insert constructor here public static void sendHome(Phone p, int newSize) { p = new Phone(newSize); p.size = 4; } public static final void main(String… params) { final var phone = new Phone(3); sendHome(phone,7); System.out.print(phone.size); } }The following is a valid constructor:public static Phone create(int size) { return new Phone(size); }The following is a valid constructor:public static Phone newInstance(int size) { return new Phone(); }The following is a valid constructor:public Phone(int size) { this.size=size; }The following is a valid constructor:public void Phone(int size) { this.size=size; }With the correct constructor, the output is 3.With the correct constructor, the output is 7.

      10 Given the following class structures, which lines can be inserted into the blank independently that would allow the class to compile? (Choose two.)public class Dinosaur { class Pterodactyl extends Dinosaur {} public void roar() { var dino = new Dinosaur(); ___________________; } }dino.Pterodactyl()Dinosaur.new Pterodactyl()dino.new Pterodactyl()new Dino().new Pterodactyl()new Dinosaur().Pterodactyl()new Dinosaur.Pterodactyl()

      11 What is the output of the Computer program?class Laptop extends Computer { public void startup() { System.out.print("laptop-"); } } public class Computer { public void startup() { System.out.print("computer-"); } public static void main(String[] args) { Computer computer = new Laptop(); Laptop laptop = new Laptop(); computer.startup(); laptop.startup(); } }computer‐laptop‐laptop‐computer‐laptop‐laptop‐The code does not compile.None of the above.

      12 What access modifier is used to mark class members package‐private?defaultfriendprotectedprivateNone of the above

      13 How many lines does the following code output?public class Cars { private static void drive() { static { System.out.println("static"); } System.out.println("fast"); { System.out.println("faster"); } } public static void main(String[] args) { drive(); drive(); } }One.Two.Three.Four.None of the above. The code does not compile.

      14 Which statements about static interface methods are correct? (Choose three.)A static interface method can be final.A static interface method can be declared private.A static interface method can be package‐private.A static interface method can be declared public.A static interface method can be declared protected.A static interface method can be declared without an access modifier.

      15 Fill in the blanks with the only option that makes this statement false: A(n) ______________ can access ______________ of the enclosing class in which it is defined.static nested class, static membersstatic nested class, instance membersmember inner class, static membersmember inner class, instance memberslocal class, instance members from within an instance methodanonymous class, instance members from within an instance method

      16 What is the result of executing the following program?public class Canine { public String woof(int bark) { return "1"+bark.toString(); } public String woof(Integer bark) { return "2"+bark.toString(); } public String woof(Object bark) { return "3"+bark.toString(); } public static void main(String[] a) { System.out.println(woof((short)5)); } }152535One line does not compile.Two lines do not compile.The program compiles but throws an exception at runtime.

      17 What statement best describes the notion of effectively final in Java?A local variable that is marked finalA static variable that is marked finalA local variable whose primitive value or object reference does not change after it is initializedA local variable whose primitive value or object reference does not change after a certain point in the methodNone of the above

      18 What is the output of the Turnip class?package animal; interface GameItem { int sell(); } abstract class Vegetable implements GameItem { public final int sell() { return 5; } } public class Turnip extends Vegetable { public final int sell() { return 3; } public static void main(String[] expensive) { System.out.print(new Turnip().sell()); } }35The code does not compile.The code compiles but throws an exception at runtime.None of the above.

      19 What is the output of the following application?package holiday; enum DaysOff { Thanksgiving, PresidentsDay, ValentinesDay } public class Vacation { public static void main(String… unused) { final DaysOff input = DaysOff.Thanksgiving; switch(input) { default: case DaysOff.ValentinesDay: System.out.print("1"); case DaysOff.PresidentsDay: System.out.print("2"); } } }1212The code does not compile.The code compiles but throws an exception at runtime.None of the above.

      20 Which statements about instance keywords are correct? (Choose two.)The that keyword can be used to read public members in the direct parent class.The this keyword can be used to read all members declared within the class.The super keyword can be used to read all members declared in a parent class.The that keyword can be used to read members of another class.The this keyword can be used to read public members in the direct parent class.The super keyword can be used in static methods.

      21 Fill in the blanks: A class ____________ an interface and ______________ an abstract class. An interface ______________ another interface.extends, extends, implementsextends, implements, extendsextends, implements, implementsimplements, extends, extendsimplements, extends, implementsimplements, implements, extends

      22 Suppose you have the following code. Which of the images best represents the state of the references c1, c2, and c3, right before the end of the main() method, assuming garbage collection hasn't run? In the diagrams, each box represents a Chicken object with a number of eggs.1: public class Chicken { 2: private Integer eggs = 2; 3: { this.eggs = 3; }