Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

JAVA Question

Download as pdf or txt
Download as pdf or txt
You are on page 1of 113

Question #1

Given:

What is the result?

A. A

2-4

B. B

0-6
1-5
2-4

C. C

1-5

Most Voted

D. D

1-5
2-4

E. E

The compilation fails due to an error in line 1.

F. F

0-6

G. G

0-6
2-4
Correct Answer:
C

Hide Answer

uestion Discussion15 ChatGPT Statistics

Share

Question #2

Given:

What is the result?

A. A

54321

B. B

C. C

nothing

D. D

543214321321211

Most Voted

Correct Answer:
C

Hide Answer
uestion Discussion12 ChatGPT Statistics

Share

Question #3

Given:

and

Which two method definitions at line n1 in the Bar class compile? (Choose two.)

A. A

public List<Number> foo(Set<String> m) {...}

B. B

public List<Integer> foo(Set<CharSequence> m) {...}

Most Voted

C. C

public List<Integer> foo(TreeSet<String> m) {...}

Most Voted

D. D

public List<Object> foo(Set<CharSequence> m) {...}

E. E

public ArrayList<Integer> foo(Set<String> m) {...}

F. F

public ArrayList<Number> foo(Set<CharSequence> m) {...}

Correct Answer:
CF
Hide Answer

uestion Discussion16 ChatGPT Statistics

Share

Question #4

Given:

What is the result?

A. A

B. B

Most Voted

C. C

D. D

An exception is thrown at runtime

Correct Answer:
B

Hide Answer
uestion Discussion8 ChatGPT Statistics

Share

Question #5

Given the code fragment:

What is the result?

A. A

0 8 10

B. B

C. C

The code prints nothing.

D. D

049

E. E

08

Most Voted
Correct Answer:
E

Question #6

Given the code fragment:

You want to display the value of currency as $100.00.


Which code inserted on line 1 will accomplish this?

A. A

NumberFormat formatter = NumberFormat.getInstance(locale).getCurrency();

B. B

NumberFormat formatter = NumberFormat.getCurrency(locale);

C. C

NumberFormat formatter = NumberFormat.getInstance(locale);

D. D

NumberFormat formatter = NumberFormat.getCurrencyInstance(locale);

Most Voted

Correct Answer:
A

Hide Answer

uestion Discussion4 ChatGPT Statistics

Share

Question #7

Which three initialization statements are correct? (Choose three.)

A. A
int[][][] e = {{1,1,1},{2,2,2}};

B. B

short sh = (short)’A’;

Most Voted

C. C

float x = 1f;

Most Voted

D. D

byte b = 10;
char c = b;

E. E

String contact# = “(+2) (999) (232)”;

F. F

int x = 12_34;

Most Voted

G. G

boolean false = (4 != 4);

Correct Answer:
CBF

Hide Answer

uestion Discussion7 ChatGPT Statistics

Share

Question #8

Your organization makes mlib.jar available to your cloud customers. While working on a new feature for
mlib.jar, you see that the customer visible method public void enableService(String hostName, String
portNumber) executes this code fragment
and you see this grant is in the security policy file:

What security vulnerability does this expose to your cloud customer's code?

A. A

privilege escalation attack against the OS running the customer code

Most Voted

B. B

SQL injection attack against the specified host and port

C. C

XML injection attack against any mlib server

D. D

none because the customer code base must also be granted SocketPermission

E. E

denial of service attack against any reachable machine

Correct Answer:
B

Hide Answer

uestion Discussion12 ChatGPT Statistics

Share

Question #9
Given:

and

What is the result?

A. A

Joe -
null

Most Voted

B. B

null
Mary

C. C

Joe -
Marry

D. D
null
null

Correct Answer:
A

Hide Answer

uestion Discussion5 ChatGPT Statistics

Share

Question #10

Given:

What is the result?

A. A

[A, B, C]
followed by an exception thrown on line 11.

B. B

[A, B, C]
[A, B]

C. C

[A, B, C]
[A, B, C]

Most Voted

D. D

On line 9, an exception is thrown at run time.


Correct Answer:
C

Question #11

Which module-info.java is correct for a service provider for a print service defined in the PrintServiceAPI
module?

A. A

module PrintServiceProvider {
requires PrintServiceAPI;
exports org.printservice.spi;
}

B. B

module PrintServiceProvider {
requires PrintServiceAPI;
provides org.printservice.spi.Print with
com.provider.PrintService;
}

Most Voted

C. C

module PrintServiceProvider {
requires PrintServiceAPI;
uses com.provider.PrintService;
}

D. D

module PrintServiceProvider {
requires PrintServiceAPI;
exports org.printservice.spi.Print with
com.provider.PrintService;
}

Correct Answer:
A
Hide Answer

uestion Discussion9 ChatGPT Statistics

Share

Question #12

Given the code fragment:

What is the result?

A. A

EUR -> 0.84 -

GBP -> 0.75 -

USD -> 1.00 -


CNY -> 6.42

B. B

The compilation fails.

C. C

CNY -> 6.42 -

EUR -> 0.84 -

GBP -> 0.75 -


USD -> 1.00
Most Voted

D. D

USD -> 1.00 -

GBP -> 0.75 -

EUR -> 0.84 -


CNY -> 6.42

Correct Answer:
B

Hide Answer

uestion Discussion5 ChatGPT Statistics

Share

Question #13

Why would you choose to use a peek operation instead of a forEach operation on a Stream?

A. A

to process the current item and return void

B. B

to remove an item from the end of the stream

C. C

to process the current item and return a stream

Most Voted

D. D

to remove an item from the beginning of the stream

Correct Answer:
C
Hide Answer

uestion Discussion3 ChatGPT Statistics

Share

Question #14

Given:

What is the result?

A. A

abcd

Most Voted

B. B

The compilation fails.


C. C

adf

D. D

abd

E. E

abdf

Correct Answer:
A

Hide Answer

uestion Discussion8 ChatGPT Statistics

Share

Question #15

Given the code fragment:


List<Integer> list = List.of(11,12,13,12,13);
Which statement causes a compile time error?

A. A

Double d = list.get(0);

Most Voted

B. B

double f = list.get(0);

C. C

Integer a = Integer.valueOf(list.get(0));

D. D

Integer b = list.get(0);

E. E

int c = list.get(0);
F. F

Double e = Double.valueOf(list.get(0));

Correct Answer:
C

Question #16

Given:

and

Which two are valid usages of the annotation? (Choose two.)

A. A

@Meal(mainCourse=”pizza”)
@Meal(dessert=”pudding”)
public class Main {
}

B. B

@Meal(mainCourse=null)
public class Main {
}

C. C

@Meal(starter=”snack”, dessert=”ice cream”)


public class Main {
}

D. D

@Meal(mainCourse=”pizza”)
@Meal(mainCourse=”salad”)
public class Main {
}

Most Voted

E. E

@Meal(mainCourse=”pizza”, starter=”snack”, dessert=”pudding”) public class Main {


}

Most Voted

Correct Answer:
BE

Hide Answer

uestion Discussion9 ChatGPT Statistics

Share

Question #17

Given:

and the code fragment:

Which three code fragments, at line n1, prints SPRING? (Choose three.)

A. A

System.out.println(Season.valueOf(“SPRING”).ordinal());

B. B

System.out.println(Season.values(1));
C. C

System.out.println(Season.SPRING);

Most Voted

D. D

System.out.println(Season.valueOf(“SPRING”));

Most Voted

E. E

System.out.println(Season.valueOf(‘s’));

F. F

System.out.println(sA[0]);

G. G

System.out.println(sA[1]);

Most Voted

Correct Answer:
BCE

Hide Answer

uestion Discussion12 ChatGPT Statistics

Share

Question #18
Given:

Which two lines of code when inserted in line 1 correctly modifies instance variables? (Choose two.)

A. A

cCount = setCCount(c);

B. B

setCCount(c) = cCount;

C. C

setGCount(g);

Most Voted

D. D

tCount = tCount;

E. E

aCount = a;

Most Voted

Correct Answer:
BD

Hide Answer
uestion Discussion5 ChatGPT Statistics

Share

Question #19

Given:

and

and

You want to print the message こんにちは Joe, 宜しくお願いします, Jane.


Which code inserted on line 1 will accomplish this?

A. A

ResourceBundle msg = ResourceBundle.getBundle(“/proj/msg/messages”, new Locale(“ja”,“JP”));


Object[] names = “Joe”, “Jane”);
String message = MessageFormat.format(msg.getString(“message”),names);

B. B

ResourceBundle msg = ResourceBundle.getBundle(“msg.messages”, Locale.JAPAN);


Object[] names = “Joe”, “Jane”);
String message = MessageFormat.format(msg.getString(“message”),names);

C. C

Locale.setDefault(Locale.JAPAN);
ResourceBundle messages = ResourceBundle.getBundle(“messages”);
String message = MessageFormat.format(msg.getString(“message”),“Joe”,“Jane”);

D. D
ResourceBundle msg = ResourceBundle.getBundle(“messages”, Locale.JAPAN);
String[] names = “Joe”, “Jane”);
String message = MessageFormat.format(msg.getString(“message”),names);

Most Voted

Correct Answer:
D

Hide Answer

uestion Discussion7 ChatGPT Statistics

Share

Question #20

Given:

and the commands:

What is the result on execution of these commands?

A. A

Test.class - > java.sql -> java.base

B. B

On execution, the jdeps command displays an error.

C. C

Test.class -> java.base -


Test.class - > java.sql

D. D

Test.class -> java.base -


Test.class - > java.sql -
java.sql -> java.base

Most Voted

Correct Answer:
C

Question #21

A company has an existing Java 8 jar file, sales-app-1.1.1.jar, that uses several Apache open source jar
files that have not been modularized.

Which module-info.java file should be used to convert sales-app-1.1.jar to a module?

A. A

module com.company.sales_app {
requires commons.beanutils;
requires org.apache.commons.collections4;
requires org.apache.commons.lang3;
requires org.apache.commons.text;
}

Most Voted

B. B

module com.company.sales_app {
requires org.apache.commons.beanutils;
requires org.apache.commons.collections4;
requires org.apache.commons.lang3;
requires org.apache.commons.text;
}

C. C

module com.company.sales_app {
requires commons.beanutils;
requires commons.collections4;
requires commons.lang3;
requires commons.text;
}

D. D

module com.company.sales_app {
requires commons.beanutils-1.9.3;
requires commons.collections4-4.2;
requires commons.lang3-3.8.1;
requires commons.text-1.3;
}

Correct Answer:
A

Hide Answer

uestion Discussion8 ChatGPT Statistics

Share

Question #22

Which two are valid statements? (Choose two.)

A. A

BiPredicate<Integer, Integer> test = (final Integer x, var y) -> (x.equals(y));

B. B

BiPredicate<Integer, Integer> test = (var x, final var y) -> (x.equals(y));

Most Voted

C. C

BiPredicate<Integer, Integer> test = (Integer x, final var y) -> (x.equals(y));

D. D

BiPredicate<Integer, Integer> test = (final var x, y) -> (x.equals(y));

E. E

BiPredicate<Integer, Integer> test = (Integer x, final Integer y) -> (x.equals(y));

Most Voted
Correct Answer:
CE

Hide Answer

uestion Discussion10 ChatGPT Statistics

Share

Question #23

Given:

and

What is the result?

A. A

Mr. Green

B. B

Green

Most Voted

C. C

An exception is thrown at runtime.


D. D

Mr. Blue

Correct Answer:
C

Hide Answer

uestion Discussion6 ChatGPT Statistics

Share

Question #24

Given:

It is required that if p instanceof Pair then p.isValid() returns true.


Which is the smallest set of visibility changes to insure this requirement is met?
A. A

left, right, setLeft, and setRight must be private.

B. B

setLeft and setRight must be protected.

C. C

left and right must be private.

Most Voted

D. D

isValid must be public.

Correct Answer:
D

Question #25

You want to read data through the reader object.


Which statement inserted on line 1 will accomplish this?

A. A

characters = reader.read();

B. B

reader.readLine();

C. C

characters.read();

D. D

reader.read(characters);

Most Voted
Correct Answer:
B

Question #26

Given:

and

Which four identifiers from the Foo and Bar classes are visible at line 1? (Choose four.)

A. A

Most Voted

B. B

Most Voted

C. C

D. D

j
Most Voted

E. E

F. F

G. G

H. H

Most Voted

I. I

J. J

Correct Answer:
CFHJ

Hide Answer

uestion Discussion5 ChatGPT Statistics

Share

Question #27

Which code fragment represents a valid Comparator implementation?

A. A

B. B
C. C

Most Voted

D. D

Correct Answer:
A

Hide Answer

uestion Discussion15 ChatGPT Statistics

Share

Question #28
Given the code fragment:

Which statement is true?

A. A

It never finishes.

Most Voted

B. B

The action of CyclicBarrier is called five times.

C. C

It finishes without any exception.

D. D

Threads in executorService execute for each of the two threads.

Correct Answer:
A

Hide Answer

uestion Discussion10 ChatGPT Statistics

Share

Question #29
Given:

What prevents this code from compiling?

A. A

The calculateSurfaceArea method within Cylinder must be declared default.

B. B

Cylinder is not properly calling the Rectangle and Ellipse interfaces’ calculateSurfaceArea methods.

C. C

Cylinder requires an implementation of calculateSurfaceArea with two parameters.

Most Voted

D. D

The calculateSurfaceArea method within Rectangle and Ellipse requires a public access modifier.

Correct Answer:
B

Hide Answer

uestion Discussion3 ChatGPT Statistics

Share

Question #30
Given a Member class with fields for name and yearsMembership, including getters and setters and a
print method, and a list of clubMembers members:

Which two Stream methods can be changed to use method references? (Choose two.)

A. A

.filter(Integer::equals(0))

B. B

.map(testName::compareToIgnoreCase)

Most Voted

C. C

.filter(Member::getYearsMembership() >= testMembershipLength)

D. D

.peek(Member::print)

Most Voted

Correct Answer:
BC

Question #31

Given:
Path p1 = Paths.get(“/scratch/exam/topsecret/answers”);
Path p2 = Paths.get(“/scratch/exam/answers/temp.txt”);
Path p3 = Paths.get(“/scratch/answers/topsecret”);
Which two statements print ..\..\..\answers\topsecret? (Choose two.)
A. A

System.out.print(p3.relativize(p1));

B. B

System.out.print(p2.relativize(p3));

Most Voted

C. C

System.out.print(p1.relativize(p3));

Most Voted

D. D

System.out.print(p3.relativize(p2));

E. E

System.out.print(p1.relativize(p2));

F. F

System.out.print(p2.relativize(p1));

Correct Answer:
AC

Hide Answer

uestion Discussion10 ChatGPT Statistics

Share

Question #32
Given the code fragment:

Which fields are serialized in a Student object?

A. A

studentNo and classes

B. B

studentNo and name

C. C

studentNo, classes and name

Most Voted

D. D

studentNo, classes, name, and address

Correct Answer:
A

Hide Answer

uestion Discussion5 ChatGPT Statistics

Share

Question #33
Given:

What is the output?

A. A

banana orange apple lemon


-----
apple banana lemon orange
-----

B. B

-----
banana orange apple lemon
-----
apple banana lemon orange

C. C

-----
-----

D. D

-----
-----
banana orange apple lemon apple banana lemon orange

Most Voted

E. E

banana orange apple lemon apple banana lemon orange


-----
-----
Correct Answer:
D

Hide Answer

uestion Discussion4 ChatGPT Statistics

Share

Question #34

and

What is the output?

A. A

Bonjour le monde!
Bonjour le monde!

B. B

Hello world!
Hello world!

C. C

Hello world!
Bonjour le monde!

Most Voted
D. D

Bonjour le monde!
Hello world!

Correct Answer:
C

Hide Answer

uestion Discussion4 ChatGPT Statistics

Share

Question #35

Given:

What is true?

A. A

A NoSuchElementException is thrown at run time.

B. B

The compilation fails.

C. C
This should print the same result each time the program runs.

D. D

This may not print the same result each time the program runs.

Most Voted

Correct Answer:
D

Question #36

Given:

What is the result?

A. A

The compilation fails.

Most Voted

B. B

[0). D, | 1). i, | 2). a]

C. C
[). o, | 1). a, | 2).]

D. D

[0). o, | 1). i, | 2). r]

E. E

ArrayIndexOutOfBounds Exception is thrown at runtime.

Correct Answer:
A

Hide Answer

uestion Discussion5 ChatGPT Statistics

Share

Question #37

Given:

What is the result?

A. A

An exception is thrown at runtime.

B. B

-3
C. C

-2

D. D

The compilation fails.

Most Voted

Correct Answer:
D

Hide Answer

uestion Discussion7 ChatGPT Statistics

Share

Question #38

Given the code fragment:

You must make the count variable thread safe.


Which two modifications meet your requirement? (Choose two.)

A. A

replace line 2 with public static synchronized void main(String[] args) {

B. B

replace line 1 with private volatile int count = 0;


C. C

replace line 3 with


synchronized(test) {
test.count++;
}

Most Voted

D. D

replace line 1 with private AtomicInteger count = new AtomicInteger(0); and replace line 3 with
test.count.incrementAndGet();

Most Voted

E. E

replace line 3 with


synchronized(test.count) {
test.count++;
}

Correct Answer:
DE

Hide Answer

uestion Discussion4 ChatGPT Statistics

Share

Question #39
Given the code fragment:

Which action enables Computator class to compile?

A. A

change Line 1 to add throws NumberFormatException

B. B

change Line 3 to Double sum = 0.0;

C. C

change Line 5 to List<Double> numbers = List.of(5, 4, 6, 3, 7, 2, 8, 1, 9);

D. D

change Line 2 to public Double sum ( C collection) {

Most Voted

E. E

change Line 4 to for (Double n : collection) {

Correct Answer:
D

Hide Answer

uestion Discussion9 ChatGPT Statistics

Share
Question #40

Given the code fragment:

What is the result?

A. A

The compilation fails due to an error in line 2.

B. B

201

C. C

de

D. D

203

E. E

The compilation fails due to an error in line 3.

Most Voted

F. F

The compilation fails due to an error in line 1.

Correct Answer:
E

Question #41

Given the code fragment:


public void foo(Function<Integer, String> fun) {...}
Which two compile? (Choose two.)

A. A
foo( n -> Integer.toHexString(n) )

Most Voted

B. B

foo( toHexString )

C. C

foo( n -> n + 1 )

D. D

foo( int n -> Integer.toHexString(n) )

E. E

foo( n -> Integer::toHexString )

F. F

foo( Integer::toHexString )

Most Voted

G. G

foo( n::toHexString )

H. H

foo( (int n) -> Integer.toHexString(n) )

Correct Answer:
AC

Hide Answer

uestion Discussion4 ChatGPT Statistics

Share

Question #42

Which declaration of an annotation type is legal?

A. A
@interface Author {
String name() default “”;
String date();
}

Most Voted

B. B

@interface Author extends Serializable {


String name() default “”;
String date();
}

C. C

@interface Author {
String name() default null;
String date();
}

D. D

@interface Author {
String name();
String date;
}

E. E

@interface Author {
String name();
String date default “”;
}

Correct Answer:
A

Hide Answer

uestion Discussion8 ChatGPT Statistics

Share

Question #43
Given:

and

and

What is the result?

A. A

The program prints Process()called 2.

Most Voted

B. B

A java.lang.NoSuchMethodException is thrown.

C. C

The program prints Process()called 1.

D. D

A java.lang.IllegalAccessException is thrown.

E. E

The compilation fails.

Correct Answer:
E

Hide Answer
uestion Discussion29 ChatGPT Statistics

Share

Question #44

Given:

Which two interfaces can be used in lambda expressions? (Choose two.)

A. A

MyInterface4

B. B

MyInterface5

C. C

MyInterface1

Most Voted

D. D

MyInterface3

Most Voted

E. E

MyInterface2
Correct Answer:
DE

Hide Answer

uestion Discussion11 ChatGPT Statistics

Share

Question #45

Given:

and

and

What is the result?

A. A

Good Night, Harry

B. B

Good Morning, Potter

C. C

Good Morning, Harry

D. D

Good Night, Potter


Most Voted

Correct Answer:
B

Question #46

What is the result?

A. A

357

Most Voted

B. B

35

C. C

235

D. D

2357

E. E

An ArrayIndexOutOfBoundsException is thrown at runtime.


Correct Answer:
A

Hide Answer

uestion Discussion7 ChatGPT Statistics

Share

Question #47

Given:

Which line of code results in a compilation error?

A. A

line n1

B. B

line n3

C. C

line n2

D. D

line n4
Most Voted

Correct Answer:
D

Hide Answer

uestion Discussion8 ChatGPT Statistics

Share

Question #48

Given the code fragment:

What is the result?

A. A

A java.lang.NullPointerException is thrown.

B. B

false

C. C

A java.lang.UnsupportedOperationException is thrown.

Most Voted

D. D

true
Correct Answer:
A

Hide Answer

uestion Discussion7 ChatGPT Statistics

Share

Question #49

Given:

and the code fragment:

What is the result?

A. A

9001: java.io.FileNotFoundException: MyFile.txt-MyFile.txt

B. B
9001: APPLICATION ERROR-9001-MyFile.txt
9001: java.io.FileNotFoundException: MyFile.txt-MyFile.txt

C. C

9001: APPLICATION ERROR-9001-MyFile.txt

Most Voted

D. D

Compilations fails at Line 1.

Correct Answer:
D

Hide Answer

uestion Discussion8 ChatGPT Statistics

Share

Question #50

Which two interfaces are considered to be functional interfaces? (Choose two.)

A. A

@FunctionalInterface
interface InterfaceC {
public boolean equals(Object o);
int breed(int x);
int calculate(int x, int y);
}

B. B

@FunctionalInterface
interface InterfaceD {
int breed(int x);
}

Most Voted

C. C
@FunctionalInterface
interface InterfaceE {
public boolean equals(int i);
int breed(int x);
}

D. D

interface InterfaceA {
int GERM = 13;
public default int getGERM() { return GERM; }
}

E. E

interface InterfaceB {
int GERM = 13;
public default int getGERM() { return get(); }
private int get() { return GERM; }
public boolean equals(Object o);
int breed(int x);
}

Most Voted

Correct Answer:
AC -

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

A. A

private java.util.ServiceLoader loader = ServiceLoader.load(Print.class)

Most Voted

B. B

private Print print = new com.service.Provider.PrintImpl();

C. C

private java.util.ServiceLoader loader = new java.util.ServiceLoader<>()

D. D
private Print print = com.service.Provider.getInstance();

Correct Answer:
A

Hide Answer

uestion Discussion6 ChatGPT Statistics

Share

Question #52

Given:

and

What is the result?

A. A

null

B. B

HH
C. C

Y@<>

D. D

The compilation fails

Most Voted

Correct Answer:
D

Hide Answer

uestion Discussion7 ChatGPT Statistics

Share

Question #53

Given:

Which is true?

A. A

Code compiles but throws a runtime exception when run.

B. B

It prints 666.

C. C

The code compiles and runs successfully but with a wrong answer (i.e., a bug).

D. D

The code does not compile successfully.


Most Voted

Correct Answer:
A

Hide Answer

uestion Discussion9 ChatGPT Statistics

Share

Question #54

Given:

and

and

What is the result?

A. A
42

Most Voted

B. B

The compilation fails due to an error in line 1.

C. C

The compilation fails due to an error in line 2.

D. D

The compilation fails due to an error in line 3.

E. E

The compilation fails due to an error in line 4.

F. F

The compilation fails due to an error in line 5.

G. G

17

Correct Answer:
G

Hide Answer

uestion Discussion9 ChatGPT Statistics

Share

Question #55

Given:

Which statement on line 1 enables this code to compile?

A. A
Consumer function = (String f) -> (System.out.println(f);};

Most Voted

B. B

Supplier function = () -> fruits.get (0);

C. C

Predicate function = a -> a.equals("banana");

D. D

Function function = x -> x.substring(0,2);

Correct Answer:
D

Question #56

Given:

What is the result?

A. A

A java.util.NoSuchElementException is thrown at run time.

Most Voted

B. B

Ans : a
C. C

The compilation fails.

D. D

Ans :

Correct Answer:
A

Hide Answer

uestion Discussion13 ChatGPT Statistics

Share

Question #57

Given:

What is the correct definition of the JsonField annotation that makes the Point class compile?

A. A

B. B
C. C

D. D

Most Voted

Correct Answer:
C

Hide Answer

uestion Discussion9 ChatGPT Statistics

Share

Question #58

Given:
What is the result?

A. A

AnotherClass#methodA()
SomeClass#methodA()

B. B

A ClassCastException is thrown at runtime.

C. C

The compilation fails.

Most Voted

D. D

AnotherClass#methodA()
AnotherClass#methodA()

E. E

SomeClass#methodA()
AnotherClass#methodA()

F. F

SomeClass#methodA()
SomeClass#methodA()
Correct Answer:
B

Hide Answer

uestion Discussion5 ChatGPT Statistics

Share

Question #59

Given:

Why does D cause a compilation error?

A. A

D does not define any method.

B. B

D inherits a() only from C.

C. C

D inherits a() from B and C but the return types are incompatible.

Most Voted

D. D

D extends more than one interface.

Correct Answer:
C
Hide Answer

uestion Discussion3 ChatGPT Statistics

Share

Question #60

Your organization provides a cloud server to your customer to run their Java code. You are reviewing the
changes for the next release and you see this change in one of the config files:

old: JAVA_OPTS="$JAVA_OPTS -Xms8g -Xmx8g"


new: JAVA_OPTS="$JAVA_OPTS -Xms8g -Xmx8g -noverify"

Which is correct?

A. A

You accept the change because -noverify is necessary for your code to run with the latest version of Java.

B. B

You reject the change because -Xms8g -Xmx8g uses too much system memory.

C. C

You accept the change because -noverify is a standard option that has been supported since Java 1.0.

D. D

You reject the change because -noverify is a critical security risk.

Most Voted

Correct Answer:
D

Given:

and
and

and

What needs to change to make these classes compile and still handle all types of Interface Worker?

A. A

Replace Line 3 with public void addProcess (Worker w) {.

B. B

Replace Line 1 with public class Main extends Thread {.

C. C

Replace Line 2 with private List processes = new ArrayList<>();.

D. D

Replace Line 3 with public void addProcess(T w) {.

Most Voted

Correct Answer:
D
Hide Answer

uestion Discussion9 ChatGPT Statistics

Share

Question #62

Given:

What is the output?

A. A

Short value 25

B. B

The compilation fails due to an error in line 1.

C. C

Byte value 25

D. D

Object value 25

Most Voted

Correct Answer:
B
Hide Answer

uestion Discussion5 ChatGPT Statistics

Share

Question #63

Given:

You replace the code on line 1 to use ParallelStream.

Which one is correct?

A. A

The code will produce the same result.

B. B

The compilation fails.

C. C

A NoSuchElementException is thrown at run time.

D. D

The code may produce a different result.

Most Voted

Correct Answer:
D

Hide Answer

uestion Discussion7 ChatGPT Statistics

Share

Question #64
Given:

You want to implement the java.io.Serializable interface to the MyPersistenceData class.

Which method should be overridden?

A. A

the readExternal method

B. B

nothing

Most Voted

C. C

the readExternal and writeExternal method

D. D

the writeExternal method

Correct Answer:
C

Hide Answer

uestion Discussion6 ChatGPT Statistics

Share

Question #65

Given:
and

and

Which three are correct? (Choose three.)

A. A

f2.foo(li) prints Hola Mundo!

B. B

b1.foo(li) prints Bonjour le monde!

C. C

b1.foo(li) prints Hello world!

D. D

f1.foo(li) prints Bonjour le monde!

Most Voted

E. E

f2.foo(li) prints Hello world!

Most Voted

F. F

f2.foo(li) prints Bonjour le monde!


G. G

f1.foo(li) prints Hola Mundo!

H. H

b1.foo(li) prints Hola Mundo!

Most Voted

I. I

f1.foo(li) prints Hello world!

Correct Answer:
A, C, I

Question #66

Given the code fragment:

What is the result?

A. A

10

B. B

C. C

The compilation fails at line 9.


D. D

The compilation fails at line 16.

E. E

The compilation fails at line 13.

Most Voted

Correct Answer:
E

Hide Answer

uestion Discussion14 ChatGPT Statistics

Share

Question #67

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. A

static String getFirstLetter() { return Alphabet.values()[1].toString();

B. B

static String getFirstLetter() { return A.toString(); }

Most Voted

C. C

final String getFirstLetter() { return A.toString(); }


D. D

String getFirstLetter() { return A.toString(); }

Correct Answer:
D

Hide Answer

uestion Discussion10 ChatGPT Statistics

Share

Question #68

Given the code fragment:

What is the result?

A. A

B. B

11

C. C

15

Most Voted

D. D

21

E. E

23
Correct Answer:
D

Hide Answer

uestion Discussion11 ChatGPT Statistics

Share

Question #69

Given the declaration:

@inteface Resource {
String[] value();
}

Examine this code fragment:

/* Loc1 */ class ProcessOrders { ... }

Which two annotations may be applied at Loc1 in the code fragment? (Choose two.)

A. A

@Resource({“Customer1”, “Customer2”})

Most Voted

B. B

@Resource(value={{}})

C. C

@Resource

D. D

@Resource(“Customer1”)

Most Voted

E. E

@Resource()
Correct Answer:
AD

Hide Answer

uestion Discussion7 ChatGPT Statistics

Share

Question #70

Given:

public interface Builder {


public A build(String str);
}

and

Assuming that this code compiles correctly, which three statements are true? (Choose three.)

A. A

A cannot be abstract.

B. B

A cannot be final.

Most Voted

C. C

B cannot be abstract.

Most Voted

D. D

B cannot be final.

E. E
B is a subtype of A.

Most Voted

F. F

A is a subtype of B.

Correct Answer:
ABD

Question #71

Given:

What is the output?

A. A

1 2 [1, 2, 3, four] 3 four

B. B

1 2 [1, 2, 3, 4] 3 4

C. C

1 2 [1, 2, 3, 4] 3 four

D. D

1 2 [1, 2, 3, four] 3 4
Most Voted

Correct Answer:
B

Hide Answer

uestion Discussion11 ChatGPT Statistics

Share

Question #72

Given the code fragment:

Which can replace line 2?

A. A

UnaryOperator u = (int i) -> i * 2;

B. B

UnaryOperator u = (var i) -> (i * 2);

Most Voted

C. C

UnaryOperator u = var i -> { return i * 2; };

D. D

UnaryOperator u = i -> { return i * 2);

Correct Answer:
B
Hide Answer

uestion Discussion5 ChatGPT Statistics

Share

Question #73

Given the content from lines.txt:

C-
C++

Java -

Go -

Kotlin -

and

What is the result?

A. A

C-
C++

Go -
Kotlin

B. B

JAVA

C. C
C-
C++

GO -
KOTLIN

D. D

C-
C++

JAVA -

GO -
KOTLIN

Most Voted

Correct Answer:
D

Hide Answer

uestion Discussion4 ChatGPT Statistics

Share

Question #74

Given:

What is the result?


A. A

1 2 followed by an exception

B. B

1245

C. C

A ConcurrentModificationException is thrown at run time.

Most Voted

D. D

1 2 3 followed by an exception

Correct Answer:
C

Hide Answer

uestion Discussion4 ChatGPT Statistics

Share

Question #75

Given:

Which change would make Foo more secure?

A. A

public String beta = "beta";


B. B

public static final String ALPHA = "alpha";

Most Voted

C. C

private String delta;

D. D

protected final String beta = "beta";

Correct Answer:
C

Question #76

Given:

public interface ExampleInterface{ }

Which two statements are valid to be written in this interface? (Choose two.)

A. A

public String methodD();

Most Voted

B. B

public int x;

C. C

final void methodG(){


System.out.println("G");
}

D. D

final void methodE();

E. E

public abstract void methodB();

Most Voted
F. F

public void methodF(){


System.out.println("F") ;
}

G. G

private abstract void methodC();

Correct Answer:
AE

Hide Answer

uestion Discussion3 ChatGPT Statistics

Share

Question #77

Given:

What is the result?

A. A

hey oh hi

B. B

yo ey
C. C

A compile time error occurs.

D. D

oh hi hey

E. E

hey oh hi yo ey

Most Voted

F. F

hey oh hi ey

Correct Answer:
E

Hide Answer

uestion Discussion2 ChatGPT Statistics

Share

Question #78

Which module defines the foundational APIs of the Java SE Platform?

A. A

java.base

Most Voted

B. B

java.se

C. C

java.lang

D. D

java.object
Correct Answer:
A

Hide Answer

uestion Discussion6 ChatGPT Statistics

Share

Question #79

Given the code fragment:

Integer i = 11;

Which two statements compile? (Choose two.)

A. A

Double c = (Double) i;

B. B

Double b = Double.valueOf(i);

Most Voted

C. C

Double a = i;

D. D

double e = Double.parseDouble(i);

E. E

double d = i;

Most Voted

Correct Answer:
AB
Hide Answer

uestion Discussion11 ChatGPT Statistics

Share

Question #80

Given:

and

and

What is the result?

A. A

The compilation fails on line 2.

B. B

ab action

Most Voted

C. C

An exception is thrown at run time.


D. D

a action

E. E

The compilation fails on line 1.

Correct Answer:
E

Question #81

Given:

Which makes class A thread safe?

A. A

Class A is thread safe.

B. B

Make foo and setB synchronized.

Most Voted

C. C

Make foo synchronized.

D. D

Make A synchronized.
E. E

Make setB synchronized.

Correct Answer:
D

Hide Answer

uestion Discussion5 ChatGPT Statistics

Share

Question #82

A company has an existing Java app that includes two Java 8 jar files, sales-8.10.jar and clients-10.2.jar.

The jar file, sales-8.10.jar, references packages in clients-10.2.jar, but clients-10.2.jar does not reference
packages in sales-8.10.jar.

They have decided to modularize clients-10.2. jar.

Which module-info.java file would work for the new library version clients-10.3.jar?

A. A

module com.company.clients{
requires com.company.clients;
}

B. B

module com.company.clients{
uses com.company.clients;
}

C. C

module com.company.clients {
exports com.company.clients.Client;
}

D. D
module com.company.clients {
exports com.company.clients;
}

Most Voted

Correct Answer:
C

Hide Answer

uestion Discussion7 ChatGPT Statistics

Share

Question #83

Which two statements are correct about modules in Java? (Choose two.)

A. A

module-info.java cannot be empty.

B. B

module-info.java can be placed in any folder inside module-path.

C. C

By default, modules can access each other as long as they run in the same folder.

D. D

A module must be declared in module-info.java file,

Most Voted

E. E

java.base exports all of the Java platforms core packages.

Most Voted

Correct Answer:
AE
Hide Answer

uestion Discussion4 ChatGPT Statistics

Share

Question #84

Assuming the user credentials are correct, which expression will create a Connection?

A. A

DriverManager.getConnection("http://database.jdbc.com", "J_SMITH", "dt12%2f3")

B. B

DriverManager.getConnection("jdbc:derby:com")

Most Voted

C. C

DriverManager.getConnection("jdbc.derby.com")

D. D

DriverManager.getConnection()

E. E

DriverManager.getConnection("J_SMITH", "dt12%2f3")

Correct Answer:
A

Hide Answer

uestion Discussion8 ChatGPT Statistics

Share

Question #85

Given:
Which is true? (Choose four.)

A. A

The compilation fails due to an error in line 4.

B. B

The compilation fails due to an error in line 9.

Most Voted

C. C

The compilation fails due to an error in line 10.

D. D

The compilation fails due to an error in line 2.

E. E

The compilation fails due to an error in line 6.

Most Voted

F. F

The compilation fails due to an error in line 7.

G. G

The compilation succeeds.

Correct Answer:
ACEF

Question #86
Given:

and the code fragment:

Which two Map objects group all employees with a salary greater than 30 by neighborhood? (Choose
two.)

A. A

Most Voted

B. B

C. C

D. D

E. E
Correct Answer:
A

Hide Answer

uestion Discussion6 ChatGPT Statistics

Share

Question #87

Given:

What is the result?

A. A

abyssinian
oxicat
korat
laperm
bengal
sphynx

B. B

abyssinian
bengal
korat
laperm
oxicat
sphynx

C. C
sphynx
oxicat
laperm
korat
bengal
abyssinian

Most Voted

D. D

nothing

Correct Answer:
C

Hide Answer

uestion Discussion8 ChatGPT Statistics

Share

Question #88

Given:

What is the result?

A. A
1.99,2.99,0

B. B

1.99,2.99,0.0

C. C

The compilation fails.

Most Voted

D. D

1.99,2.99

Correct Answer:
B

Hide Answer

uestion Discussion5 ChatGPT Statistics

Share

Question #89

Given:

and
Which statement is true?

A. A

The memory allocated for Jack object can be reused in line 2.

B. B

The memory allocated for Jane object can be reused in line 1.

C. C

The memory allocated for Jane object can be reused in line 2.

D. D

The memory allocated for John object can be reused in line 1.

Most Voted

Correct Answer:
A

Hide Answer

uestion Discussion1 ChatGPT Statistics

Share

Question #90
Given:

and

Why does this compilation fail?

A. A

The method X.print (object) is not accessible to Y.

B. B

The method Y.print (Object) does not call the method super.print (Object).

C. C

In method X.print (Collection), System.out::println is an invalid Java identifier.


D. D

The method Y.print (Object...) cannot override the final method X.print (Object...).

Most Voted

E. E

The method print (Object) and the method print (Object...) are duplicates of each other.

Correct Answer:
D

Question #91

Given:

Which loop incurs a compile time error?

A. A

the loop starting line 11

Most Voted

B. B

the loop starting line 7

C. C
the loop starting line 14

D. D

the loop starting line 3

Correct Answer:
A

Hide Answer

uestion Discussion4 ChatGPT Statistics

Share

Question #92

Given the code fragment:

Which statement prints the same value of result? (Choose two.)

A. A

System.out.printIn(IntStream.range(0, 99).count());

B. B

System.out.printIn(IntStream.rangeClosed(1, 100).count());

Most Voted

C. C

System.out.printIn(IntStream.range(1, 100).count());

D. D

System.out.printIn(IntStream.rangeClosed(0, 100).map(x -> x).count());


Correct Answer:
BD

Hide Answer

uestion Discussion7 ChatGPT Statistics

Share

Question #93

Given:

What is the result?

A. A

385

B. B

C. C

The compilation fails.

D. D

80

Most Voted

E. E

25

Correct Answer:
A
Hide Answer

uestion Discussion2 ChatGPT Statistics

Share

Question #94

Which two var declarations are correct? (Choose two.)

A. A

var names = new ArrayList<>();

Most Voted

B. B

var _ = 100;

C. C

var var = “hello”;

Most Voted

D. D

var y = null;

E. E

var a;

Correct Answer:
AC

Hide Answer

uestion Discussion3 ChatGPT Statistics

Share

Question #95
Given:

Which two changes need to be made to make this class compile? (Choose two.)

A. A

Change Line 1 to a class:


public class API {

B. B

Change Line 2 to an abstract method:


public abstract void checkValue(Object value)
throws IllegalArgumentException;

Most Voted

C. C

Change Line 2 access modifier to protected:


protected void checkValue(Object value)
throws IllegalArgumentException;

D. D

Change Line 1 to extend java.lang.AutoCloseable:


public interface API extends AutoCloseable {

E. E
Change Line 1 to an abstract class:
public abstract class API {

Most Voted

Correct Answer:
BE

Question #96

Given:

and

and

What code inserted into class C would allow it to compile?

A. A

public void x() { }


public void z() { }

Most Voted
B. B

public void x() { }


protected void y() { super.y(); }
public void z() { }

C. C

void x() { }
public void y() { }
public void z() { }

D. D

void x() { super.y(); }


public void z() { }

E. E

void x() { }
public void z() { }

Correct Answer:
A

Hide Answer

uestion Discussion3 ChatGPT Statistics

Share

Question #97

Given:

Which three classes successfully override showFirst()? (Choose three.)

A. A
Most Voted

B. B

Most Voted

C. C

D. D

E. E

Most Voted

F. F
Correct Answer:
ABE

Hide Answer

uestion Discussion3 ChatGPT Statistics

Share

Question #98

Given:

and

Which two lines can replace line 1 so that the Y class compiles? (Choose two.)

A. A
super.set(List map)

B. B

map.forEach((k, v) -> set(v)));

C. C

set(map.values());

Most Voted

D. D

set(map)

E. E

super.set(map.values());

Most Voted

Correct Answer:
CE

Hide Answer

uestion Discussion3 ChatGPT Statistics

Share

Question #99

Given the code fragment:


What is the result?

A. A

B. B

It prints 1 in infinite loop.

C. C

D. D

The program prints nothing.

Most Voted

E. E

Correct Answer:
D

Hide Answer

uestion Discussion2 ChatGPT Statistics

Share

Question #100

Given TripleThis.java:
Compiling TripleThis.java gives this compiler warning:

Note: TripleThis.java uses unchecked or unsafe operations.

Which two replacements remove this compiler warning and prints 12? (Choose two.)

A. A

Replace line 12 with public static void printValue(Function f, int num) {

Most Voted

B. B

Replace line 12 with public static void printValue(Function f, T num) {

C. C

Replace line 9 with Function tripler = x —> { return (Integer) x * 3; }

D. D

Replace line 12 with public static void printValue(Function f, Integer num) {

Most Voted

E. E

Replace line 9 with Function tripler = x -> { return x * 3; }

F. F

Replace line 9 with Function tripler = x -> [ return x * 3; ]

Correct Answer:
AD
Question #101

Given the code fragment:

What change on line 1 will make this code compile?

A. A

Add catch(M | L e)

B. B

Add catch(L e)

Most Voted

C. C

Add catch(N | L | M e)

D. D

Add catch(L | N e)

E. E

Add catch(L | M | N e)
Correct Answer:
B

Hide Answer

uestion Discussion2 ChatGPT Statistics

Share

Question #102

Given the code fragment:

Which two code snippets inserted independently inside println method print Mondial:domainmodel?
(Choose two.)

A. A

Main.prefix + Main.name

B. B

prefix + getName

C. C

Main.prefix + Main.getName()

Most Voted

D. D

new Main().prefix + new Main().name


Most Voted

E. E

prefix + name

F. F

prefix + Main.name

Correct Answer:
BC

Hide Answer

uestion Discussion9 ChatGPT Statistics

Share

Question #103

Given the code fragment:

What is the result?

A. A

[Lettuce, Kale]

B. B
A compilation error is thrown.

C. C

[Lettuce, Kale]
[Seabass, Salmon]

Most Voted

D. D

[Kale, Lettuce]
[Salmon, Seabass]

Correct Answer:
B

Hide Answer

uestion Discussion3 ChatGPT Statistics

Share

Question #104

Given:

Automobile.java -

Car.java -
What must you do so that the code prints 4?

A. A

Remove the parameter from wheels method in line 3.

Most Voted

B. B

Remove abstract keyword in line 1.

C. C

Replace the code in line 2 with Car ob = new Car();.

D. D

Add @Override annotation at line 2.

Correct Answer:
A

Hide Answer

uestion Discussion3 ChatGPT Statistics

Share

Question #105

Which module is required for any application using Swing or AWT?

A. A
java.desktop

Most Voted

B. B

java.prefs

C. C

java.se

D. D

java.logging

E. E

java.rmi

Correct Answer:
A

You might also like