OCP Oracle Certified Professional Java SE 11 Developer Practice Tests. Jeanne Boyarsky
Чтение книги онлайн.
Читать онлайн книгу OCP Oracle Certified Professional Java SE 11 Developer Practice Tests - Jeanne Boyarsky страница 18
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[] ohMy) { String animal1 = new String("lion"); String animal2 = new String("tiger"); String animal3 = new String("bear"); animal3 = animal1; animal2 = animal3; animal1 = animal2; }NoneOneTwoThreeNone of the above
110 Suppose Panther and Cub are interfaces and neither contains any default methods. Which statements are true? (Choose two.)If Panther has a single abstract method, Cub is guaranteed to be a functional interface.If Panther has a single abstract method, Cub may be a functional interface.If Panther has a single abstract method, Cub cannot be a functional interface.If Panther has two abstract methods, Cub is guaranteed to be a functional interface.If Panther has two abstract methods, Cub may be a functional interface.If Panther has two abstract methods, Cub cannot be a functional interface.
111 A local class can access which type of local variables? (Choose two.)finalprivateeffectively finalstaticdefaultconst
112 What does the following output?1: public class InitOrder { 2: public String first = "instance"; 3: public InitOrder() { 4: first = "constructor"; 5: } 6: { first = "block"; } 7: public void print() { 8: System.out.println(first); 9: } 10: public static void main(String… args) { 11: new InitOrder().print(); 12: } 13: }blockconstructorinstanceThe code does not compile.None of the above.
113 Which statement about the following interface is correct?public interface Tree { public static void produceSap() { growLeaves(); } public abstract int getNumberOfRings() { return getNumberOfRings(); } private static void growLeaves() { produceSap(); } public default int getHeight() { return getHeight (); } }The code compiles.The method produceSap() does not compile.The method getNumberOfRings() does not compile.The method growLeaves() does not compile.The method getHeight() does not compile.The code does not compile because it contains a cycle.
114 Which statements about a variable with a type of var are true? (Choose two.)The variable can be assigned null at any point in the program.The variable can be assigned null only after initial initialization.The variable can never be assigned null.Only primitives can be used with the variable.Only objects can be used with the variable.Either a primitive or an object can be used with the variable.
115 Assume there is a class Bouncer with a protected variable. Methods in which class can access this variable?Any subclass of Bouncer or any class in the same package as BouncerAny superclass of BouncerOnly subclasses of BouncerOnly classes in the same package as BouncerNone of the above
116 What is the output of the following application?package forest; public class Woods { static class Tree {} public static void main(String[] leaves) { int heat = 2; int water = 10-heat; final class Oak extends Tree { // p1 public int getWater() { return water; // p2 } } System.out.print(new Oak().getWater()); water = 0; } }8Line p1 contains a compiler error.Line p2 contains a compiler error.Another line of code contains a compiler error.None of the above.
117 Which can fill in the blank to make the code compile? (Choose two.)interface Australian {} interface Mammal {} ________________ Australian, Mammal {}class Quokka extendsclass Quokka implementsNeither A nor B. Only one interface can be specified.interface Quokka extendsinterface Quokka implementsNeither D nor E. Only one interface can be specified.
118 What is true of the following method?public void setColor(String color) { color = color; }It is a correctly implemented accessor method.It is a correctly implemented mutator method.It is an incorrectly implemented accessor method.It is an incorrectly implemented mutator method.None of the above.
119 Which of the following statements about calling this() in a constructor are true? (Choose three.)If arguments are provided to this(), then there must be a constructor in the class able to take those arguments.If arguments are provided to this(), then there must be a constructor in the superclass able to take those arguments.If the no‐argument this() is called, then the class must explicitly implement the no‐argument constructor.If super() and this() are both used in the same constructor, super() must appear on the line immediately after this().If super() and this() are both used in the same constructor, this() must appear on the line immediately after super().If this() is used, it must be the first line of the constructor.
120 What is the result of compiling and executing the following class?public class RollerSkates { static int wheels = 1; int tracks = 5; public static void main(String[] arguments) { RollerSkates s = new RollerSkates(); int feet=4, tracks = 15; System.out.print(feet + tracks + s.wheels); } }The code does not compile.451020
121 Which statements about the following program are correct? (Choose two.)package vessel; class Problem extends Exception {} abstract class Danger { protected abstract void isDanger() throws Problem; // m1 } public class SeriousDanger extends Danger { // m2 protected void isDanger() throws Exception { // m3 throw new RuntimeException(); // m4 } public static void main(String[] w) throws Throwable { // m5 var sd = new SeriousDanger().isDanger(); // m6 } }The code does not compile because of line m1.The code does not compile because of line m2.The code does not compile because of line m3.The code does not compile because of line m4.The code does not compile because of line m5.The code does not compile because of line m6.
122 Which statements about top‐level and member inner classes are correct? (Choose three.)Both can be marked protected.Only top‐level classes can be declared final.Both can declare constructors.Member inner classes cannot be marked private.Member inner classes can access private variables of the top‐level class in which it is defined.Both can be marked abstract.
123 What is required to define a valid Java class file?A class declarationA package statementAn import statementA class declaration and package statementA class declaration and at least one import statementThe public modifier
124 How many objects are eligible for garbage collection right before the end of the main() method?1: public class Person { 2: public Person youngestChild; 3: 4: public static void main(String… args) { 5: Person elena = new Person(); 6: Person janeice = new Person(); 7: elena.youngestChild = janeice; 8: janeice = null; 9: Person zoe = new Person(); 10: elena.youngestChild = zoe; 11: zoe = null; 12: } }None.One.Two.Three.The code does not compile.
125 What is the output of the following application?package race; interface Drive { int SPEED = 5; default int getSpeed() { return SPEED; } } interface Hover { int MAX_SPEED = 10; default int getSpeed() { return MAX_SPEED; } } public class Car implements Drive, Hover { public static void main(String[] gears) { class RaceCar extends Car { @Override public int getSpeed() { return 15; } }; System.out.print(new RaceCar().getSpeed()); } }51015The code does not compile.The answer cannot be determined with the information given.
126 What is the output of the following application? (Choose two.)1: public class ChooseWisely { 2: public ChooseWisely() { super(); } 3: public int choose(int choice) { return 5; } 4: public int choose(short choice) { return 2; } 5: public int choose(long choice) { return 11; } 6: public int choose(double choice) { return 6; } 7: public int choose(Float choice) { return 8; } 8: public static void main(String[] path) { 9: ChooseWisely c = new ChooseWisely(); 10: System.out.println(c.choose(2f)); 11: System.out.println(c.choose((byte)2+1)); 12: } 13: }23568
127 Fill in the blanks: It is possible to extend a(n) ______________ but not a(n) ______________. (Choose two.)interface, abstract classanonymous class, static nested classabstract class, enumenum, interfaceabstract class, interfacelocal class, anonymous class
128 How