Название: OCP Oracle Certified Professional Java SE 11 Developer Practice Tests
Автор: Jeanne Boyarsky
Издательство: John Wiley & Sons Limited
Жанр: Программы
isbn: 9781119696148
isbn:
169 How many lines of the following class contain compilation errors?1: class Fly { 2: public Fly Fly() { return Fly(); } 3: public void Fly(int kite) {} 4: public int Fly(long kite) { return 1; } 5: public static void main(String[] a) { 6: var f = new Fly(); 7: f.Fly(); 8: } 9: }None.One.Two.Three.Four.The answer cannot be determined with the information given.
170 How many of the classes in the figure can write code that references the sky() method?NoneOneTwoThreeFour
171 For the diagram in the previous question, how many classes can write code that references the light variable?NoneOneTwoThreeFour
172 Given the following method signature, which classes cannot call it?protected void run(String government)All classes in other packagesAll classes in the same packageSubclasses in a different packageSubclasses in the same package
173 What is the output of the following application?interface Toy { String play(); } public class Gift { public static void main(String[] matrix) { abstract class Robot {} class Transformer extends Robot implements Toy { public String name = "GiantRobot"; public String play() {return "DinosaurRobot";} // y1 } Transformer prime = new Transformer () { public String play() {return name;} // y2 }; System.out.print(prime.play()+" "+name); } }GiantRobot GiantRobotGiantRobot DinosaurRobotDinosaurRobot DinosaurRobotThe code does not compile because of line y1.The code does not compile because of line y2.None of the above.
174 What is the output of the HighSchool application?package edu; import java.io.FileNotFoundException; abstract class School { abstract Float getNumTeachers(); public int getNumStudents() { return 10; } } public class HighSchool extends School { final Float getNumTeachers() { return 4f; } public int getNumStudents() throws FileNotFoundException { return 20; } public static void main(String[] s) throws Exception { var school = new HighSchool(); System.out.print(school.getNumStudents()); } }10204.0One line of the program does not compile.Two lines of the program do not compile.None of the above.
175 What is the output of the following application?package track; interface Run { default CharSequence walk() { return "Walking and running!"; } } interface Jog { default String walk() { return "Walking and jogging!"; } } public class Sprint implements Run, Jog { public String walk() { return "Sprinting!"; } public static void main(String[] args) { var s = new Sprint(); System.out.println(s.walk()); } }Walking and running!Walking and jogging!Sprinting!The code does not compile.The code compiles but prints an exception at runtime.None of the above.
176 What is true of these two interfaces?interface Crawl { void wriggle(); } interface Dance { public void wriggle(); }A concrete class can implement both, but must implement wriggle().A concrete class can implement both, but must not implement wriggle().A concrete class would only be able to implement both if the public modifier were removed but must implement wriggle().If the public modifier were removed, a concrete class can implement both, but must not implement wriggle().None of the above.
177 Which of these are functional interfaces?interface Lion { public void roar(); default void drink() {} boolean equals(Lion lion); } interface Tiger { public void roar(); default void drink() {} String toString(String name); }LionTigerBoth Lion and TigerNeither is a functional interface.The code does not compile.
178 How many lines of the following class contain a compiler error?1: public class Dragon { 2: boolean scaly; 3: static final int gold; 4: Dragon protectTreasure(int value, boolean scaly) { 5: scaly = true; 6: return this; 7: } 8: static void fly(boolean scaly) { 9: scaly = true; 10: } 11: int saveTheTreasure(boolean scaly) { 12: return this.gold; 13: } 14: static void saveTheDay(boolean scaly) { 15: this.gold = 0; 16: } 17: static { gold = 100; } 18: }NoneOneTwoThreeMore than three
179 What is true of the following method?public String getColor() { return 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.
180 Which statement is true?You can always change a method signature from call(String[] arg) to call(String… arg) without causing a compiler error in the calling code.You can always change a method signature from call(String… arg) to call(String[] arg) without causing a compiler error in the existing code.Both of the above.Neither of the above.
181 What are two motivations for marking a class final? (Choose two.)Guarantee behavior of a classAllow the class to be extendedImprove securitySupport polymorphismImprove performanceEnsure the contents of the class are immutable
182 Which statement about the following interface is correct?public interface Planet { int circumference; public abstract void enterAtmosphere(); public default int getCircumference() { enterAtmosphere(); return circumference; } private static void leaveOrbit() { var earth = new Planet() { public void enterAtmosphere() {} }; earth.getCircumference(); } }The code compiles.The method enterAtmosphere() does not compile.The method getCircumference() does not compile.The method leaveOrbit() does not compile.The code does not compile for a different reason.None of the above.
183 Fill in the blanks: ___________________ methods always have the same name but a different list of parameters, while ___________________ methods always have the same name and the same return type.Overloaded, overriddenInherited, overriddenOverridden, overloadedHidden, overloadedOverridden, hiddenNone of the above
184 What is the output of the following program?public class Husky { { this.food = 10; } { this.toy = 2; } private final int toy; private static int food; public Husky(int friend) { this.food += friend++; this.toy -= friend--; } public static void main(String… unused) { var h = new Husky(2); System.out.println(h.food+","+h.toy); } }12,‐112,213,‐1Exactly one line of this class does not compile.Exactly two lines of this class do not compile.None of the above.
185 Suppose you have the following code. Which of the images best represents the state of the references right before the end of the main() method, assuming garbage collection hasn't run?1: public class Link { 2: private String name; 3: private Link next; 4: public Link(String name, Link next) { 5: this.name = name; 6: this.next = next; 7: } 8: public void setNext(Link next) { 9: this.next = next; 10: } 11: public Link getNext() { 12: return next; 13: } 14: public static void main(String… args) { 15: var apple = new Link("x", null); 16: var orange = new Link("y", apple); 17: var banana = new Link("z", orange); 18: orange.setNext(banana); 19: banana.setNext(orange); 20: apple = null; 21: banana = null; 22: } 23: }Option A.Option B.Option C.Option D.The code does not compile.None of the above.
186 Which statement about a no‐argument constructor is true?The Java compiler will always insert a default no‐argument constructor if you do not define a no‐argument constructor in your class.For a class to call super() in one of its constructors, its parent class must explicitly implement a no‐argument constructor.If a class extends another class that has only one constructor that takes a value, then the child class must explicitly declare at least one constructor.A class may contain more than one no‐argument constructor.
187 Which variable declaration is the first line not to compile?public class Complex { class Building {} class House extends Building{} public void convert() { Building b1 = new Building(); House h1 = new House(); Building b2 = new House(); Building b3 = (House) b1; House h2 = (Building) h1; Building b4 = (Building) b2; House h3 = (House) b2; } }b3h2b4h3All of the lines compile.
188 What is the output of the following application?1: interface Tasty { 2: default void eat() { 3: System.out.print("Spoiled!"); 4: } } 5: public class ApplePicking { 6: public static void main(String[] food) { 7: var apple = new Tasty() { 8: @Override 9: void eat() { 10: System.out.print("Yummy!"); 11: } 12: } 13: } }Spoiled!Yummy!The application completes without printing anything.One line of this application fails to compile.Two lines of this application fail to compile.None of the above.
189 Which СКАЧАТЬ