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



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

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 many lines of the following program do not compile?1: public enum Color { 2: RED(1,2) { void toSpectrum() {} }, 3: BLUE(2) { void toSpectrum() {} void printColor() {} }, 4: ORANGE() { void toSpectrum() {} }, 5: GREEN(4); 6: public Color(int… color) {} 7: abstract void toSpectrum(); 8: final void printColor() {} 9: }ZeroOneTwoThreeMore than three

      129 What is the output of the Square program?package shapes; abstract class Trapezoid { private int getEqualSides() {return 0;} } abstract class Rectangle extends Trapezoid { public static int getEqualSides() {return 2;} // x1 } public final class Square extends Rectangle { public int getEqualSides() {return 4;} // x2 public static void main(String[] corners) { final Square myFigure = new Square(); // x3 System.out.print(myFigure.getEqualSides()); } }024The code does not compile due to line x1.The code does not compile due to line x2.The code does not compile due to line x3.

      130 What can fill in the blank so the play() method can be called from all classes in the com.mammal package, but not the com.mammal.gopher package?package com.mammal; public class Enrichment {