Summer Sale Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: ecus65

Oracle 1z0-830 - Java SE 21 Developer Professional

Page: 2 / 3
Total 84 questions

Given:

java

List abc = List.of("a", "b", "c");

abc.stream()

.forEach(x -> {

x = x.toUpperCase();

});

abc.stream()

.forEach(System.out::print);

What is the output?

A.

abc

B.

An exception is thrown.

C.

Compilation fails.

D.

ABC

Given:

java

sealed class Vehicle permits Car, Bike {

}

non-sealed class Car extends Vehicle {

}

final class Bike extends Vehicle {

}

public class SealedClassTest {

public static void main(String[] args) {

Class vehicleClass = Vehicle.class;

Class carClass = Car.class;

Class bikeClass = Bike.class;

System.out.print("Is Vehicle sealed? " + vehicleClass.isSealed() +

"; Is Car sealed? " + carClass.isSealed() +

"; Is Bike sealed? " + bikeClass.isSealed());

}

}

What is printed?

A.

Is Vehicle sealed? true; Is Car sealed? true; Is Bike sealed? true

B.

Is Vehicle sealed? false; Is Car sealed? false; Is Bike sealed? false

C.

Is Vehicle sealed? true; Is Car sealed? false; Is Bike sealed? false

D.

Is Vehicle sealed? false; Is Car sealed? true; Is Bike sealed? true

Which of the following statements are correct?

A.

You can use 'private' access modifier with all kinds of classes

B.

You can use 'protected' access modifier with all kinds of classes

C.

You can use 'public' access modifier with all kinds of classes

D.

You can use 'final' modifier with all kinds of classes

E.

None

Given:

java

try (FileOutputStream fos = new FileOutputStream("t.tmp");

ObjectOutputStream oos = new ObjectOutputStream(fos)) {

fos.write("Today");

fos.writeObject("Today");

oos.write("Today");

oos.writeObject("Today");

} catch (Exception ex) {

// handle exception

}

Which statement compiles?

A.

fos.write("Today");

B.

fos.writeObject("Today");

C.

oos.write("Today");

D.

oos.writeObject("Today");

What do the following print?

java

public class DefaultAndStaticMethods {

public static void main(String[] args) {

WithStaticMethod.print();

}

}

interface WithDefaultMethod {

default void print() {

System.out.print("default");

}

}

interface WithStaticMethod extends WithDefaultMethod {

static void print() {

System.out.print("static");

}

}

A.

nothing

B.

default

C.

Compilation fails

D.

static

Given:

java

var counter = 0;

do {

System.out.print(counter + " ");

} while (++counter < 3);

What is printed?

A.

0 1 2 3

B.

0 1 2

C.

1 2 3 4

D.

1 2 3

E.

An exception is thrown.

F.

Compilation fails.

Given:

java

public class OuterClass {

String outerField = "Outer field";

class InnerClass {

void accessMembers() {

System.out.println(outerField);

}

}

public static void main(String[] args) {

System.out.println("Inner class:");

System.out.println("------------");

OuterClass outerObject = new OuterClass();

InnerClass innerObject = new InnerClass(); // n1

innerObject.accessMembers(); // n2

}

}

What is printed?

A.

markdown

Inner class:

------------

Outer field

B.

Nothing

C.

An exception is thrown at runtime.

D.

Compilation fails at line n1.

E.

Compilation fails at line n2.

Given:

java

public class Test {

static int count;

synchronized Test() {

count++;

}

public static void main(String[] args) throws InterruptedException {

Runnable task = Test::new;

Thread t1 = new Thread(task);

Thread t2 = new Thread(task);

t1.start();

t2.start();

t1.join();

t2.join();

System.out.println(count);

}

}

What is the given program's output?

A.

It's either 1 or 2

B.

It's either 0 or 1

C.

It's always 2

D.

It's always 1

E.

Compilation fails

Given:

java

public class ThisCalls {

public ThisCalls() {

this(true);

}

public ThisCalls(boolean flag) {

this();

}

}

Which statement is correct?

A.

It does not compile.

B.

It throws an exception at runtime.

C.

It compiles.

What do the following print?

java

public class Main {

int instanceVar = staticVar;

static int staticVar = 666;

public static void main(String args[]) {

System.out.printf("%d %d", new Main().instanceVar, staticVar);

}

static {

staticVar = 42;

}

}

A.

666 42

B.

666 666

C.

42 42

D.

Compilation fails