OCP Oracle Certified Professional Java SE 11 Developer Practice Tests. Jeanne Boyarsky

OCP Oracle Certified Professional Java SE 11 Developer Practice Tests - Jeanne Boyarsky


Скачать книгу
is the output of the following application?package jungle; public class RainForest extends Forest { public RainForest(long treeCount) { this.treeCount = treeCount+1; } public static void main(String[] birds) { System.out.print(new RainForest(5).treeCount); } } class Forest { public long treeCount; public Forest(long treeCount) { this.treeCount = treeCount+2; } }568The code does not compile.

      195 What is the result of compiling and executing the following class?package sports; public class Bicycle { String color = "red"; private void printColor(String color) { color = "purple"; System.out.print(color); } public static void main(String[] rider) { new Bicycle().printColor("blue"); } }redpurpleblueIt does not compile.

      196 Given that Short and Integer extend Number directly, what type can be used to fill in the blank in the following class to allow it to compile?package band; interface Horn { public Integer play(); } abstract class Woodwind { public Short play() { return 3; } } public final class Saxophone extends Woodwind implements Horn { public _________ play() { return null; } }ObjectIntegerShortNumberNone of the above

      197 Which statements about abstract classes and methods are correct? (Choose three.)An abstract class can be extended by a final class.An abstract method can be overridden by a final method.An abstract class can be extended by multiple classes directly.An abstract class can extend multiple classes directly.An abstract class cannot implement an interface.An abstract class can extend an interface.

      198 Given the following enum declaration, how many lines contain compilation errors?public enum Proposition { TRUE(1) { String getNickName() { return "RIGHT"; }}, FALSE(2) { public String getNickName() { return "WRONG"; }}, UNKNOWN(3) { public String getNickName() { return "LOST"; }} public int value; Proposition(int value) { this.value = value; } public int getValue() { return this.value; } protected abstract String getNickName(); }ZeroOneTwoThreeMore than three

      199 Which statements about Java classes are true? (Choose three.)A Java class file may include more than one package statement.A Java class file may include more than one import statement.A Java class file may contain more than one comment.Any instance fields within a class must be defined after the class name.Any instance fields within a class must be defined before the class name.Java supports macros, in which fragments of code within a class may be defined inside a Java file, separate from any top‐level type declaration.

      200 What is the result of executing the HopCounter program?// Hopper.java package com.animals; public class Hopper { protected void hop() { System.out.println("hop"); } } // Grasshopper.java package com.insect; import com.animals.Hopper; public class Grasshopper extends Hopper { public void move() { hop(); // p1 } } // HopCounter.java package com.insect; public class HopCounter { public static void main(String[] args) { var hopper = new Grasshopper(); hopper.move(); // p2 hopper.hop(); // p3 } } The code prints hop once.The code prints hop twice.The first compiler error is on line p1.The first compiler error is on line p2.The first compiler error is on line p3.

      201 Which of the following is not an attribute common to both abstract classes and interfaces?They both can contain abstract methods.They both can contain public methods.They both can contain protected methods.They both can contain static variables.

      202 Given the following class, which method signature could be successfully added to the class as an overloaded version of the findAverage() method?public class Calculations { public Integer findAverage(int sum) { return sum; } }public Long findAverage(int sum)public Long findAverage(int sum, int divisor)public Integer average(int sum)private void findAverage(int sum)

      203 Which of the following is a valid method name in Java? (Choose two.)Go_$Outside$2()have‐Fun()new()9enjoyTheWeather()$sprint()walk#()

      204 Fill in the blanks: A functional interface must contain or inherit ______________ and may optionally include ______________.at least one abstract method, the @Override annotationexactly one method, static methodsexactly one abstract method, the @FunctionalInterface annotationat least one static method, at most one default methodNone of the above

      205 Fill in the blank with the line of code that allows the program to compile and print 15 at runtime.package love; interface Sport { private int play() { return 15; } } interface Tennis extends Sport { private int play() { return 30; } } public class Game implements Tennis { public int play() { return ______________; } public static void main(String… ace) { System.out.println(new Game().play()); } }Sport.play()Sport.super.play()Sport.Tennis.play()Tennis.Sport.super.play()The code does not compile regardless of what is inserted into the blank.None of the above.

      206 What is the output of the following program?public class MoreMusic { { System.out.print("do-"); System.out.print("re-"); } public MoreMusic() { System.out.print("mi-"); } public MoreMusic(int note) { this(null); System.out.print("fa-"); } public MoreMusic(String song) { this(9); System.out.print("so-"); } public static void main(String[] sound) { System.out.print("la-"); var play = new MoreMusic(1); } }la‐do‐re‐mi‐so‐fa‐la‐do‐re‐mi‐fa‐do‐re‐mi‐fa‐so‐la‐fa‐re‐do‐mi‐so‐The code does not compile.None of the above.

      207 Given the following two classes in the same package, what is the result of executing the Hug program?public class Kitten { /** private **/ float cuteness; /* public */ String name; // default double age; void meow() { System.out.println(name + " - "+cuteness); } } public class Hug { public static void main(String… friends) { var k = new Kitten(); k.cuteness = 5; k.name = "kitty"; k.meow(); } }kitty ‐ 5.0The Kitten class does not compile.The Hug class does not compile.The Kitten and Hug classes do not compile.None of the above.

      208 Which expressions about enums used in switch statements are correct? (Choose two.)The name of the enum type must not be used in each case statement.A switch statement that takes a enum value may not use ordinal() numbers as case statement matching values.The name of the enum type must be used in each case statement.Every value of the enum must be present in a case statement.A switch statement that takes a enum value can use ordinal() numbers as case statement matching values.Every value of the enum must be present in a case statement unless a default branch is provided.

      209 What is the output of the following application?package prepare; interface Ready { static int first = 2; final short DEFAULT_VALUE = 10; GetSet go = new GetSet(); // n1 } public class GetSet implements Ready { int first = 5; static int second = DEFAULT_VALUE; // n2 public static void main(String[] begin) { var r = new Ready() {}; System.out.print(r.first); // n3 System.out.print(" " + second); // n4 } }2 105 10The code does not compile because of line n1.The code does not compile because of line n2.The code does not compile because of line n3.The code does not compile because of line n4.

      210 What is the result of executing the Tortoise program?// Hare.java package com.mammal; public class Hare { public void init() { System.out.print("init-"); } private void race() { System.out.print("hare-"); } } // Tortoise.java package com.reptile; import com.mammal.Hare; public class Tortoise { protected void race(Hare hare) { hare.init(); // x1 hare.race(); // x2 System.out.print("tortoise-"); } public static void main(String[] args) { var tortoise = new Tortoise(); var hare = new Hare(); tortoise.race(hare); } }init‐hare‐tortoiseinit‐hareThe first line with a compiler error is line x1.The first line with a compiler error is line x2.The code does not compile due to a different line.The code throws an exception.

      211 What is the result of executing the Sounds program?// Sheep.java package com.mammal; public class Sheep { private void baa() { System.out.println("baa!"); } private static void speak() { baa(); } } // Sounds.java package com.animals; import com.mammal.Sheep; public class Sounds { public static void main(String[] args) { var sheep = new Sheep(); sheep.speak(); } }The code runs and prints baa!.The Sheep class does not compile.The Sounds class does not compile.Neither class compiles.

      212 What is the output of the Helicopter program?package flying; class Rotorcraft { protected final int height = 5; abstract int fly(); } interface CanFly {} public class Helicopter extends Rotorcraft implements CanFly { private int height = 10; protected int fly() { return super.height; } public static void main(String[] unused) { Helicopter h = (Helicopter)new Rotorcraft(); System.out.print(h.fly()); } }510The code does not compile.The code compiles but produces a ClassCastException at runtime.None of the above.

      213 Which


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