Tag Archives: code

Given the code fragment: List<Integer> list = List.of(11,12,13,12,13); Which statement causes a

Given the code fragment:List<Integer> list = List.of(11,12,13,12,13);Which statement causes a compile time error? A. Integer a = Integer.valueOf(list.get(0)); B. Double e = Double.valueOf(list.get(0)); C. int c =list.get(0); D. Double d = list.get(0); E. Integer b = list.get(0); F. double f = list.get(0); Correct Answer: A

Given the code fragment: public void foo(Function&lt;Integer, String&gt; fun) {…} Which two compile?

Given the code fragment:public void foo(Function<Integer, String> fun) {…}Which two compile? (Choose two.) A. foo( n -> Integer.toHexString(n) ) B. foo( toHexString ) C. foo( n -> n + 1 ) D. foo( int n -> Integer.toHexString(n) ) E. foo( n -> Integer::toHexString ) F. foo( Integer::toHexString ) G. foo( n::toHexString ) H. foo( (int n) -> Integer.toHexString(n)… Read More »

Given the code fragment: Which two code snippets inserted independently inside print method print Mondial:

Given the code fragment:Which two code snippets inserted independently inside print method print Mondial: domainmodal? A. new Main (} .prefix + new Main().name B. Main.prefix + Main.name C. prefix + Main, name D. prefix + getName E. Main.prefix + Main.getName() F. prefix + name Correct Answer: A,C

Given this enum declaration: (Exhibit) Examine this code: System.out.println(Alphabet.getFirstLetter());

Given this enum declaration:Examine this code:System.out.println(Alphabet.getFirstLetter());What code should be written at line 3 to make this code print A? A. static String getFirstLetter() { return A.toString(); } B. String getFirstLetter() { return A.toString(); } C. static String getFirstLetter() { return Alphabet.values()[1].toString(); } D. final String getFirstLetter() { return A.toString(); } Correct Answer: A

Which code fragment does a service use to load the service provider with a Print interface?

Which code fragment does a service use to load the service provider with a Print interface? A. private Print print = new com.service.Provider.PrintImpl(); B. private Print print = com.service.Provider.getInstance(); C. private java.util.ServiceLoader<Print> loader = new java.util.ServiceLoader<> (); D. private java.util.ServiceLoader<Print> loader = ServiceLoader.load (Print.class); Correct Answer: D

Analyze the code: (Exhibit) Which two options can you insert inside println method to produce Global:namescope?

Analyze the code:Which two options can you insert inside println method to produce Global:namescope? (Choose two.) A. new Test().prefix+new Test().name B. prefix+name C. Test.prefix+Test.getName() D. Test.getName+prefix E. Test.prefix+Test.name F. prefix+Test.name Correct Answer: A,C

Assuming the Widget class has a getPrice method, this code does not compile: (Exhibit) Which two statements,

Assuming the Widget class has a getPrice method, this code does not compile:Which two statements, independently, would allow this code to compile? (Choose two.) A. Replace line 4 with Stream<Widget> widgetStream = widgets.stream();. B. Replace line 5 with widgetStream.filter(a > ((Widget)a).getPrice() > 20.00). C. Replace line 1 with List<Widget> widgetStream = widgets.stream();. D. Replace line 5 with widgetStream.filter((Widget… Read More »