Pass the Oracle Java SE 1z0-830 Questions and answers with CertsForce

Viewing page 3 out of 3 pages
Viewing questions 21-30 out of questions
Questions # 21:

Given:

java

StringBuffer us = new StringBuffer("US");

StringBuffer uk = new StringBuffer("UK");

Stream stream = Stream.of(us, uk);

String output = stream.collect(Collectors.joining("-", "=", ""));

System.out.println(output);

What is the given code fragment's output?

Options:

A.

US-UK


B.

An exception is thrown.


C.

-US=UK


D.

=US-UK


E.

Compilation fails.


F.

US=UK


Expert Solution
Questions # 22:

Given:

java

void verifyNotNull(Object input) {

boolean enabled = false;

assert enabled = true;

assert enabled;

System.out.println(input.toString());

assert input != null;

}

When does the given method throw a NullPointerException?

Options:

A.

A NullPointerException is never thrown


B.

Only if assertions are enabled and the input argument is null


C.

Only if assertions are disabled and the input argument is null


D.

Only if assertions are enabled and the input argument isn't null


E.

Only if assertions are disabled and the input argument isn't null


Expert Solution
Questions # 23:

Given:

java

Integer frenchRevolution = 1789;

Object o1 = new String("1789");

Object o2 = frenchRevolution;

frenchRevolution = null;

Object o3 = o2.toString();

System.out.println(o1.equals(o3));

What is printed?

Options:

A.

true


B.

false


C.

A NullPointerException is thrown.


D.

A ClassCastException is thrown.


E.

Compilation fails.


Expert Solution
Questions # 24:

Which methods compile?

Options:

A.

```java public List getListSuper() { return new ArrayList(); }

csharp


B.

```java

public List getListExtends() {

return new ArrayList();

}


C.

```java public List getListExtends() { return new ArrayList(); }

csharp


D.

```java

public List getListSuper() {

return new ArrayList();

}


Expert Solution
Questions # 25:

Given:

java

public class Versailles {

int mirrorsCount;

int gardensHectares;

void Versailles() { // n1

this.mirrorsCount = 17;

this.gardensHectares = 800;

System.out.println("Hall of Mirrors has " + mirrorsCount + " mirrors.");

System.out.println("The gardens cover " + gardensHectares + " hectares.");

}

public static void main(String[] args) {

var castle = new Versailles(); // n2

}

}

What is printed?

Options:

A.

nginx

Hall of Mirrors has 17 mirrors.

The gardens cover 800 hectares.


B.

Nothing


C.

An exception is thrown at runtime.


D.

Compilation fails at line n1.


E.

Compilation fails at line n2.


Expert Solution
Viewing page 3 out of 3 pages
Viewing questions 21-30 out of questions