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



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

key, String… harmonies) { this.sing(key); } public void sing_re(int note, String… sound, String key) { this.sing(key); } public void sing_me(String… keys, String… pitches) { this.sing(key); } public void sing_far(String key, String… harmonies) { this.Singing.sing(key); } public void sing_so(int note, String… sound, String key) { this.Singing.sing(key); } public void sing_la(String… keys, String… pitches) { this.Singing.sing(key); } }ZeroOneTwoThreeFourFive

      92 What is the output of the following application?package world; public class Matrix { private int level = 1; class Deep { private int level = 2; class Deeper { private int level = 5; public void printReality(int level) { System.out.print(this.level+" "); System.out.print(Matrix.Deep.this.level+" "); System.out.print(Deep.this.level); } } } public static void main(String[] bots) { Matrix.Deep.Deeper simulation = new Matrix() .new Deep().new Deeper(); simulation.printReality(6); } }1 1 25 2 25 2 16 2 26 2 1The code does not compile.

      93 Given that Integer and Long are direct subclasses of Number, what type can be used to fill in the blank in the following class to allow it to compile?package orchestra; interface MusicCreator { public Number play(); } abstract class StringInstrument { public Long play() {return 3L;} } public class Violin extends StringInstrument implements MusicCreator { public _________ play() { return null; } }LongIntegerLong or IntegerLong or NumberLong, Integer, or NumberNone of the above

      94 What is the output of the RightTriangle program?package shapes; abstract class Triangle { abstract String getDescription(); } abstract class IsoRightTriangle extends RightTriangle { // g1 public String getDescription() { return "irt"; } } public class RightTriangle extends Triangle { protected String getDescription() { return "rt"; } // g2 public static void main(String[] edges) { final var shape = new IsoRightTriangle(); // g3 System.out.print(shape.getDescription()); } }rtirtThe code does not compile due to line g1.The code does not compile due to line g2.The code does not compile due to line g3.None of the above.

      95 What is the output of the following program?interface Dog { private void buryBone() { chaseTail(); } private static void wagTail() { chaseTail(); } public default String chaseTail() { return "So cute!"; } } public class Puppy implements Dog { public String chaseTail() throws IllegalArgumentException { throw new IllegalArgumentException("Too little!"); } public static void main(String[] t) { var p = new Puppy(); System.out.print(p.chaseTail()); } }So cute!An exception is thrown with a Too little! message.A different exception is thrown.The code does not compile because buryBone() is not used.The code does not compile because chaseTail() cannot declare any exceptions in the Puppy class.None of the above.

      96 Which of the following are advantages of using enumerated types in Java, rather than static constant values? (Choose three.)Improve performance.Provide access to fixed set of constants whose values do not change during the course of the application.Provide a caller with a list of available values for a parameter within a method.Ensure consistency of data across an application.Add support for concurrency.Offer ability to create new enumerated values at runtime.

      97 How do you force garbage collection to occur at a certain point?Calling System.forceGc()Calling System.gc()Calling System.requireGc()Calling GarbageCollection.clean()None of the above

      98 Which changes made to the following class would help to properly encapsulate the data in the class?package shield; public class Protect { private String material; protected int strength; public int getStrength() { return strength; } public void setStrength(int strength) { this.strength = strength; } }Add a getter method for material.Add a setter method for material.Change the access modifier of material to protected.Change the access modifier of strength to private.None of the above.

      99 Which are true statements about referencing variables from a lambda? (Choose two.)Instance and static variables can be used regardless of whether effectively final.Instance and local variables can be used regardless of whether effectively final.Instance variables and method parameters must be effectively final to be used.Local variables and method parameters must be effectively final to be used.Local and static variables can be used regardless of whether effectively final.Method parameters and static variables can be used regardless of whether effectively final.

      100 Given the following two classes, each in a different package, which line inserted into the code allows the second class to compile?package commerce; public class Bank { public void withdrawal(int amountInCents) {} public void deposit(int amountInCents) {} } package employee; // INSERT CODE HERE public class Teller { public void processAccount(int deposit, int withdrawal) { withdrawal(withdrawal); deposit(deposit); } }import static commerce.Bank.*;import static commerce.Bank;static import commerce.Bank.*;static import commerce.Bank;None of the above

      101 Given the following structure, which snippets of code return true? (Choose three.)interface Friendly {} abstract class Dolphin implements Friendly {} class Animal implements Friendly {} class Whale extends Object {} public class Fish {} class Coral extends Animal {}new Coral() instanceof Friendlynull instanceof Objectnew Coral() instanceof Objectnew Fish() instanceof Friendlynew Whale() instanceof Objectnew Dolphin() instanceof Friendly

      102 What is true of the following code?public class Eggs { enum Animal { CHICKEN(21), PENGUIN(75); private int numDays; private Animal(int numDays) { this.numDays = numDays; } public int getNumDays() { return numDays; } public void setNumDays(int numDays) { this.numDays = numDays; } } public static void main(String[] args) { Animal chicken = Animal.CHICKEN; chicken.setNumDays(20); System.out.print(chicken.getNumDays()); System.out.print(" "); System.out.print(Animal.CHICKEN.getNumDays()); System.out.print(" "); System.out.print(Animal.PENGUIN.getNumDays()); } }It prints 20 20 20It prints 20 20 75It prints 20 21 75It prints 21 21 75It does not compile due to setNumDays().It does not compile for another reason.

      103 What statement about the following interface is correct?1: public interface Thunderstorm { 2: float rain = 1; 3: char getSeason() { return 'W'; } 4: boolean isWet(); 5: private static void hail() {} 6: default String location() { return "Home"; } 7: private static int getTemp() { return 35; } 8: }Line 2 does not compile.Line 3 does not compile.Line 4 does not compile.Line 5 does not compile.Line 6 does not compile.Line 7 does not compile.All of the lines compile.

      104 What is the output of the following application?package finance; enum Currency { DOLLAR, YEN, EURO } abstract class Provider { protected Currency c = Currency.EURO; } public class Bank extends Provider { protected Currency c = Currency.DOLLAR; public static void main(String[] pennies) { int value = 0; switch(new Bank().c) { case 0: value--; break; case 1: value++; break; } System.out.print(value); } }‐101The Provider class does not compile.The Bank class does not compile.None of the above.

      105 How many lines need to be removed for this code to compile?1: package figures; 2: public class Dolls { 3: public int num() { return 3.0; } 4: public int size() { return 5L; } 5: 6: public void nested() { nested(2,true); } 7: public int nested(int w, boolean h) { return 0; } 8: public int nested(int level) { return level+1; } 9: 10: public static void main(String[] outOfTheBox) { 11: System.out.print(new Dolls().nested()); 12: } 13: }ZeroOneTwoThreeFourFive

      106 Fill in the blanks: A class may be assigned to a(n) ___________________ reference variable automatically but requires an explicit cast when assigned to a(n) ___________________ reference variable.subclass, outer classsuperclass, subclassconcrete class, subclasssubclass, superclassabstract class, concrete class

      107 Which statement about functional interfaces is incorrect?A functional interface can have any number of static methods.A functional interface can have any number of default methods.A functional interface can have any number of private static methods.A functional interface can have any number of abstract methods.A functional interface can have any number of private methods.All of the above are correct.

      108 What are possible outputs of the following given that the comment on line X can be replaced by code?// Mandrill.java public class Mandrill { public int age; public Mandrill(int age) { this.age = age; } public String toString() { return "" + age; } } // PrintAge.java public class PrintAge { public static void main (String[] args) { var mandrill = new Mandrill(5); // line X System.out.println(mandrill); } }05Either 0 or 5Any int valueDoes not compile

      109 How many of the String objects are eligible for garbage collection right before the end of the main() method?public static void main(String[]