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



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

is the output of the following application?package space; public class Bottle { public static class Ship { private enum Sail { // w1 TALL {protected int getHeight() {return 100;}}, SHORT {protected int getHeight() {return 2;}}; protected abstract int getHeight(); } public Sail getSail() { return Sail.TALL; } } public static void main(String[] stars) { var bottle = new Bottle(); Ship q = bottle.new Ship(); // w2 System.out.print(q.getSail()); } }TALLThe code does not compile because of line w1.The code does not compile because of line w2.The code does not compile for another reason.The code compiles, but the application does not produce any output at runtime.None of the above.

      47 Which of the following is not a valid order for elements within a class?Constructor, instance variables, method declarationsInstance variables, static initializer constructor, method declarationsMethod declarations, instance variables, constructorInstance initializer, constructor, instance variables, constructorNone of the above

      48 Which line of code, inserted at line p1, causes the application to print 5?package games; public class Jump { private int rope = 1; protected boolean outside; public Jump() { // line p1 outside = true; } public Jump(int rope) { this.rope = outside ? rope : rope+1; } public static void main(String[] bounce) { System.out.print(new Jump().rope); } }this(4);new Jump(4);this(5);rope = 4;super(4);super(5);

      49 Which of the following is not a reason to use encapsulation when designing a class? (Choose two.)Improve security.Increase concurrency and improve performance.Maintain class data integrity of data elements.Prevent users from modifying the internal attributes of a class.Prevent variable state from changing.Promote usability by other developers.

      50 Which statement about the following program is correct? (Choose two.)package ballroom; class Leader {} class Follower {} abstract class Dancer { public Leader getPartner() { return new Leader(); } abstract public Leader getPartner(int count); // u1 } public abstract class SwingDancer extends Dancer { public Leader getPartner(int x) { return null; } public Follower getPartner() { // u2 return new Follower(); // u3 } public static void main(String[] args) { new SwingDancer().getPartner(); // u4 } }The code does not compile because of line u1.The code does not compile because of line u2.The code does not compile because of line u3.The code does not compile because of line u4.At least three of the classes compile without issue.All of the classes compile without issue.

      51 Which is not a true statement given this diagram? Assume all classes are public.Instance methods in the Blanket class can call the Flashlight class's turnOn().Instance methods in the Flashlight class can call the Flashlight class's replaceBulb().Instance methods in the Phone class can call the Blanket class's wash().Instance methods in the Tent class can call the Tent class's pitch().None of the above.

      52 Given the diagram in the previous question, how many of the classes shown in the diagram can call the display() method?ZeroOneTwoThreeFour

      53 Which of the following statements are correct? (Choose two.)Java allows multiple inheritance using two abstract classes.Java allows multiple inheritance using two interfaces.Java does not allow multiple inheritance.An interface can extend another interface.An interface can implement another interface.

      54 Which statement about the following code is correct?public class Dress { int size = 10; default int getSize() { display(); return size; } static void display() { System.out.print("What a pretty outfit!"); } private int getLength() { display(); return 15; } private static void tryOn() { display(); } }The code contains an invalid constant.The method getSize() does not compile.The method getLength() does not compile.The method tryOn() does not compile.The code compiles.None of the above.

      55 What is the output of the following application?package ocean; abstract interface CanSwim { public void swim(final int distance); } public class Turtle { final int distance = 2; public static void main(String[] seaweed) { final int distance = 3; CanSwim seaTurtle = { final int distance = 5; @Override public void swim(final int distance) { System.out.print(distance); } }; seaTurtle.swim(7); } }2357The code does not compile.None of the above.

      56 What is the output of the following application?package pet; public class Puppy { public static int wag = 5; // q1 public void Puppy(int wag) { // q2 this.wag = wag; } public static void main(String[] tail) { System.out.print(new Puppy(2).wag); // q3 } }25The first line with a compiler error is line q1.The first line with a compiler error is line q2.The first line with a compiler error is line q3.

      57 Given the following method signature, which classes can call it?void run(String government)Classes in other packagesClasses in the same packageSubclasses in a different packageAll classesNone of the above

      58 Which is the first declaration to not compile?package desert; interface CanBurrow { public abstract void burrow(); } @FunctionalInterface interface HasHardShell extends CanBurrow {} abstract class Tortoise implements HasHardShell { public abstract int toughness(); } public class DesertTortoise extends Tortoise { public int toughness() { return 11; } }The CanBurrow interface does not compile.The HasHardShell interface does not compile.The Tortoise interface does not compile.The DesertTortoise interface does not compile.All of the interfaces compile.

      59 Which is the first line to not compile?interface Building { default Double getHeight() { return 1.0; } // m1 } interface Office { public default String getHeight() { return null; } // m2 } abstract class Tower implements Building, Office {} // m3 public class Restaurant extends Tower {} // m4Line m1Line m2Line m3Line m4None of the above

      60 What is the output of the following code snippet?String tree = "pine"; int count = 0; if (tree.equals("pine")) { int height = 55; count = count + 1; } System.out.print(height + count);15556It does not compile.

      61 Which of the following are valid comments in Java? (Choose three.)/****** TODO */# Fix this bug later' Error closing pod bay doors/ Invalid record //* Page not found */// IGNORE ME

      62 Which of the following modifiers can both be applied to a method? (Choose three.)private and finalabstract and finalstatic and privateprivate and abstractabstract and staticstatic and protected

      63 Given the following class, what should be inserted into the two blanks to ensure the class data is properly encapsulated?package storage; public class Box { public String stuff; __________ String __________() { return stuff; } public void setStuff(String stuff) { this.stuff = stuff; } }private and getStuffprivate and isStuffpublic and getStuffpublic and isStuffNone of the above

      64 How many rows of the following table contain an error?Interface memberMembership typeRequires method body?Static methodClassYesPrivate non‐static methodClassYesAbstract methodInstanceNoDefault methodInstanceNoPrivate static methodClassYesZeroOneTwoThreeFour

      65 Fill in the blanks: ___________________ is used to call a constructor in the parent class, while ___________________ is used to reference a member of the parent class.super and this()super and super()super() and thissuper() and superNone of the above

      66 What is the output of the Watch program?1: class SmartWatch extends Watch { 2: private String getType() { return "smart watch"; } 3: public String getName(String suffix) { 4: return getType() + suffix; 5: } 6: } 7: public class Watch { 8: private String getType() { return "watch"; } 9: public String getName(String suffix) { 10: return getType() + suffix; 11: } 12: public static void main(String[] args) { 13: var watch = new Watch(); 14: var smartWatch = new SmartWatch(); 15: System.out.print(watch.getName(",")); 16: System.out.print(smartWatch.getName("")); 17: } 18: }smart watch,watchwatch,smart watchwatch,watchThe code does not compile.An exception is printed at runtime.None of the above.

      67 What is the output of the Movie program?package theater; class Cinema { private String name = "Sequel"; public Cinema(String name) { this.name = name; } } public class Movie extends Cinema { private String name = "adaptation"; public Movie(String movie) { this.name = "Remake"; } public static void main(String[] showing) { System.out.print(new Movie("Trilogy").name); } }SequelTrilogyRemakeAdaptationnullNone of the above

      68 Where can a final instance variable be assigned a value? (Choose three.)Instance initializerstatic initializerInstance methodOn the line it is declaredClass constructorstatic method

      69 What is the output of the following code?public class Bunny { static interface Rabbit { } static class FlemishRabbit implements Rabbit { } private static void hop(Rabbit