.
Чтение книги онлайн.

Читать онлайн книгу - страница 13

Название:

Автор:

Издательство:

Жанр:

Серия:

isbn:

isbn:

СКАЧАТЬ 10; 3: public static void main(String[] data) { 4: var trees = 5; 5: System.out.print(trees+birds); 6: } 7: }It compiles and outputs 5.It compiles and outputs 15.It does not compile.It compiles but throws an exception at runtime.

      5 Fill in the blanks: The ___________________ access modifier allows access to everything the ___________________ access modifier does and more.package‐private, protectedprivate, package‐privateprivate, protectedprivate, publicpublic, privateNone of the above

      6 Which set of modifiers, when added to a default method within an interface, prevents it from being overridden by a class implementing the interface?constfinalstaticprivateprivate staticNone of the above

      7 Given the following application, fill in the missing values in the table starting from the top and going downward.package competition; public class Robot { static String weight = "A lot"; double ageMonths = 5, ageDays = 2; private static boolean success = true; public void main(String[] args) { final String retries = "1"; // P1 } }Variable TypeNumber of Variables Accessible at P1Class_____Instance_____Local_____2, 0, 12, 2, 11, 0, 10, 2, 1

      8 Given the following code, what values inserted, in order, into the blank lines allow the code to compile? (Choose two.)_______ agent; public _______ Banker { private static _______ getMaxWithdrawal() { return 10; } }package, new, intpackage, class, longimport, class, null//, class, intimport, interface, voidpackage, class, void

      9 Which of the following are correct? (Choose two.)public class Phone { private int size; // insert constructor here public static void sendHome(Phone p, int newSize) { p = new Phone(newSize); p.size = 4; } public static final void main(String… params) { final var phone = new Phone(3); sendHome(phone,7); System.out.print(phone.size); } }The following is a valid constructor:public static Phone create(int size) { return new Phone(size); }The following is a valid constructor:public static Phone newInstance(int size) { return new Phone(); }The following is a valid constructor:public Phone(int size) { this.size=size; }The following is a valid constructor:public void Phone(int size) { this.size=size; }With the correct constructor, the output is 3.With the correct constructor, the output is 7.

      10 Given the following class structures, which lines can be inserted into the blank independently that would allow the class to compile? (Choose two.)public class Dinosaur { class Pterodactyl extends Dinosaur {} public void roar() { var dino = new Dinosaur(); ___________________; } }dino.Pterodactyl()Dinosaur.new Pterodactyl()dino.new Pterodactyl()new Dino().new Pterodactyl()new Dinosaur().Pterodactyl()new Dinosaur.Pterodactyl()

      11 What is the output of the Computer program?class Laptop extends Computer { public void startup() { System.out.print("laptop-"); } } public class Computer { public void startup() { System.out.print("computer-"); } public static void main(String[] args) { Computer computer = new Laptop(); Laptop laptop = new Laptop(); computer.startup(); laptop.startup(); } }computer‐laptop‐laptop‐computer‐laptop‐laptop‐The code does not compile.None of the above.

      12 What access modifier is used to mark class members package‐private?defaultfriendprotectedprivateNone of the above

      13 How many lines does the following code output?public class Cars { private static void drive() { static { System.out.println("static"); } System.out.println("fast"); { System.out.println("faster"); } } public static void main(String[] args) { drive(); drive(); } }One.Two.Three.Four.None of the above. The code does not compile.

      14 Which statements about static interface methods are correct? (Choose three.)A static interface method can be final.A static interface method can be declared private.A static interface method can be package‐private.A static interface method can be declared public.A static interface method can be declared protected.A static interface method can be declared without an access modifier.

      15 Fill in the blanks with the only option that makes this statement false: A(n) ______________ can access ______________ of the enclosing class in which it is defined.static nested class, static membersstatic nested class, instance membersmember inner class, static membersmember inner class, instance memberslocal class, instance members from within an instance methodanonymous class, instance members from within an instance method

      16 What is the result of executing the following program?public class Canine { public String woof(int bark) { return "1"+bark.toString(); } public String woof(Integer bark) { return "2"+bark.toString(); } public String woof(Object bark) { return "3"+bark.toString(); } public static void main(String[] a) { System.out.println(woof((short)5)); } }152535One line does not compile.Two lines do not compile.The program compiles but throws an exception at runtime.

      17 What statement best describes the notion of effectively final in Java?A local variable that is marked finalA static variable that is marked finalA local variable whose primitive value or object reference does not change after it is initializedA local variable whose primitive value or object reference does not change after a certain point in the methodNone of the above

      18 What is the output of the Turnip class?package animal; interface GameItem { int sell(); } abstract class Vegetable implements GameItem { public final int sell() { return 5; } } public class Turnip extends Vegetable { public final int sell() { return 3; } public static void main(String[] expensive) { System.out.print(new Turnip().sell()); } }35The code does not compile.The code compiles but throws an exception at runtime.None of the above.

      19 What is the output of the following application?package holiday; enum DaysOff { Thanksgiving, PresidentsDay, ValentinesDay } public class Vacation { public static void main(String… unused) { final DaysOff input = DaysOff.Thanksgiving; switch(input) { default: case DaysOff.ValentinesDay: System.out.print("1"); case DaysOff.PresidentsDay: System.out.print("2"); } } }1212The code does not compile.The code compiles but throws an exception at runtime.None of the above.

      20 Which statements about instance keywords are correct? (Choose two.)The that keyword can be used to read public members in the direct parent class.The this keyword can be used to read all members declared within the class.The super keyword can be used to read all members declared in a parent class.The that keyword can be used to read members of another class.The this keyword can be used to read public members in the direct parent class.The super keyword can be used in static methods.

      21 Fill in the blanks: A class ____________ an interface and ______________ an abstract class. An interface ______________ another interface.extends, extends, implementsextends, implements, extendsextends, implements, implementsimplements, extends, extendsimplements, extends, implementsimplements, implements, extends

      22 Suppose you have the following code. Which of the images best represents the state of the references c1, c2, and c3, right before the end of the main() method, assuming garbage collection hasn't run? In the diagrams, each box represents a Chicken object with a number of eggs.1: public class Chicken { 2: private Integer eggs = 2; 3: { this.eggs = 3; } 4: public Chicken(int eggs) { 5: this.eggs = eggs; 6: } 7: public static void main(String[] r) { 8: var c1 = new Chicken(1); 9: var c2 = new Chicken(2); 10: var c3 = new Chicken(3); 11: c1.eggs = c2.eggs; 12: c2 = c1; 13: c3.eggs = null; 14: } }Option A.Option B.Option C.Option D.The code does not compile.None of the above.

      23 What is the output of the following application?package musical; interface Speak { default int talk() { return 7; } } interface Sing { default int talk() { return 5; } } public class Performance implements Speak, Sing { public int talk(String… x) { return x.length; } public static void main(String[] notes) { System.out.print(new Performance().talk()); } }75The code does not compile.The code compiles without issue, but the output cannot be determined until runtime.None of the above.

      24 What is the output of the following application?package ai; interface Pump { void pump(double psi); } interface Bend extends Pump { void bend(double tensileStrength); } public class Robot { public static final void apply( Bend instruction, double input) { instruction.bend(input); } public static void main(String… СКАЧАТЬ