OCP Oracle Certified Professional Java SE 11 Developer Practice Tests. Jeanne Boyarsky
Чтение книги онлайн.
Читать онлайн книгу OCP Oracle Certified Professional Java SE 11 Developer Practice Tests - Jeanne Boyarsky страница 16
70 Which of the following results is not a possible output of this program?package sea; enum Direction { north, south, east, west; }; public class Ship { public static void main(String[] compass) { System.out.print(Direction.valueOf(compass[0])); } }WEST is printed.south is printed.An ArrayIndexOutOfBoundsException is thrown at runtime.An IllegalArgumentException is thrown at runtime.All of the above are possible.
71 Which statement about encapsulation is not true?Encapsulation allows putting extra logic in the getter and setter methods.Encapsulation can use immutable instance variables in the implementation.Encapsulation causes two classes to be more tightly tied together.Encapsulation makes it easier to change the instance variables in the future.All of the above are true.
72 What is the output of the following application?package radio; public class Song { public void playMusic() { System.out.print("Play!"); } private static void playMusic() { System.out.print("Music!"); } private static void playMusic(String song) { System.out.print(song); } public static void main(String[] tracks) { new Song().playMusic(); } }Play!Music!The code does not compile.The code compiles, but the answer cannot be determined until runtime.
73 Which of the following statements about overriding a method are correct? (Choose three.)The return types must be covariant.The access modifier of the method in the child class must be the same or narrower than the method in the superclass.The return types must be the same.A checked exception thrown by the method in the parent class must be thrown by the method in the child class.A checked exception thrown by a method in the child class must be the same or narrower than the exception thrown by the method in the parent class.The access modifier of the method in the child class must be the same or broader than the method in the superclass.
74 How lines of the following code do not compile?10: interface Flavor { 11: public default void happy() { 12: printFlavor("Rocky road"); 13: } 14: private static void excited() { 15: printFlavor("Peanut butter"); 16: } 17: private void printFlavor(String f) { 18: System.out.println("Favorite Flavor is: "+f); 19: } 20: public static void sad() { 21: printFlavor("Butter pecan"); 22: } 23: } 24: public class IceCream implements Flavor { 25: @Override public void happy() { 26: printFlavor("Cherry chocolate chip"); 27: } }None, they all compileOneTwoThreeFourFive or more
75 Of the following four modifiers, choose the one that is not implicitly applied to all interface variables.finalabstractstaticpublic
76 Given the following method, what is the first line that does not compile?public static void main(String[] args) { int Integer = 0; // k1 Integer int = 0; // k2 Integer ++; // k3 int++; // k4 int var = null; // k5 }k1k2k3k4k5
77 What is the result of compiling and executing the following class?public class Tolls { private static int yesterday = 1; int tomorrow = 10; public static void main(String[] args) { var tolls = new Tolls(); int today = 20, tomorrow = 40; // line x System.out.print( today + tolls.tomorrow + tolls.yesterday); // line y } }The code does not compile due to line x.The code does not compile due to line y.3161
78 What is the output of the following application?package weather; public class Forecast { public enum Snow { BLIZZARD, SQUALL, FLURRY @Override public String toString() { return "Sunny"; } } public static void main(String[] modelData) { System.out.print(Snow.BLIZZARD.ordinal() + " "); System.out.print(Snow.valueOf("flurry".toUpperCase())); } }0 FLURRY1 FLURRY0 Sunny1 SunnyThe code does not compile.None of the above.
79 Which of the following is not a true statement?The first line of every constructor is a call to the parent constructor via the super() command.A class is not required to have a constructor explicitly defined.A constructor may pass arguments to the parent constructor.A final instance variable whose value is not set when it is declared or in an initialization block should be set by the constructor.None of the above.
80 What can fill in the blank so the play() method can be called from all classes in the com.mammal and com.mammal.eland package, but not the com.mammal.gopher package?package com.mammal; public class Enrichment { ______ void play() {} }Leave it blank.privateprotectedpublicNone of the above.
81 What is the output of the Rocket program?package transport; class Ship { protected int weight = 3; private int height = 5; public int getWeight() { return weight; } public int getHeight() { return height; } } public class Rocket extends Ship { public int weight = 2; public int height = 4; public void printDetails() { System.out.print(super.getWeight()+","+super.height); } public static final void main(String[] fuel) { new Rocket().printDetails(); } }2,53,45,23,5The code does not compile.None of the above.
82 Imagine you are working with another team to build an application. You are developing code that uses a class that the other team has not finished writing yet. You want to allow easy integration once the other team's code is complete. Which statements would meet this requirement? (Choose two.)An abstract class is best.An interface is best.Either of an abstract class or interface would meet the requirement.The methods should be protected.The methods should be public.The methods should be static.
83 Fill in the blank with the line of code that allows the program to compile and print 10 at runtime.interface Speak { public default int getVolume() { return 20; } } interface Whisper { public default int getVolume() { return 10; } } public class Debate implements Speak, Whisper { public int getVolume() { return 30; } public static void main(String[] a) { var d = new Debate(); System.out.println(______________); } }Whisper.d.getVolume()d.Whisper.getVolume()Whisper.super.getVolume()d.Whisper.super.getVolume()The code does not compile regardless of what is inserted into the blank.None of the above.
84 Which of the following properties of an enum can be marked abstract?The enum type definitionAn enum methodAn enum valueAn enum constructorNone of the above
85 How many lines does the following code output?public class Cars { static { System.out.println("static"); } private static void drive() { System.out.println("fast"); } { System.out.println("faster"); } public static void main(String[] args) { drive(); drive(); } }One.Two.Three.Four.Five.None of the above. The code does not compile.
86 Suppose foo is a reference to an instance of a class Foo. Which of the following is not possible about the variable reference foo.bar?bar is an instance variable.bar is a static variable.bar is a local variable.It can be used to read from bar.It can be used to write to bar.All of the above are possible.
87 The following diagram shows two reference variables pointing to the same Bunny object in memory. The reference variable myBunny is of type Bunny, while unknownBunny is a valid but unknown data type. Which statements about the reference variables are true? Assume the instance methods and variables shown in the diagram are marked public. (Choose three.)The reference type of unknownBunny must be Bunny or a supertype of Bunny.The reference type of unknownBunny cannot be cast to a reference type of Bunny.The reference type of unknownBunny must be Bunny or a subclass of Bunny.If the reference type of unknownBunny is Bunny, it has access to all of the same methods and variables as myBunny.The reference type of unknownBunny could be an interface, class, or abstract class.If the reference type of unknownBunny is Object, it has access to all of the same methods and variables as myBunny without a cast.
88 Which of the following interface methods are inherited by classes that implement the interface? (Choose two.)private methodsprivate static methodsdefault methodsstatic methodsabstract methodsfinal methods
89 Which of these are functional interfaces?interface Lion { public void roar(); default void drink() {} String toString(); } interface Tiger { public void roar(); default void drink() {} int hashCode(); }LionTigerBoth Lion and TigerNeither is a functional interface.The code does not compile.
90 Given the following code, which lines when placed independently in the blank allow the code to compile and print bounce? (Choose two.)public class TennisBall