JAVA QUESTIONS total list
JAVA QUESTIONS total list
Given:
public class Tester {
Correct Answer:
C
Question #3
Given:
import java.util.*;
}
and
import java.util.*;
//line n1
Which two method definitions at line n1 in the Bar class compile? (Choose two.)
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
Question #4
Given:
sb.append("HOWDY");
36.insert(0,1);
sb.replace(3, 5, "LL");
1
What is the result?
A. A
5
B. B
4
Most Voted
C. C
3
D. D
An exception is thrown at runtime
Correct Answer:
B
Question #5
Correct Answer:
E
Question #6
Correct Answer:
A
Question #7
Correct Answer:
CBF
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
try {
accessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
transportSocket = new Socket(hostname, portNumber);
return null;
});
}
and you see this grant is in the security policy file:
grant codebase "file:${mlib.home}/j2se/home/mlib.jar" {
permission java.io.SocketPermission "*", "connect";
};
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
Question #9
Given:
Correct Answer:
A
Question #10
Given:
List<String> list1 = new ArrayList<>();
list1.add("A");
list1.add("B");
List<String> list2 = Collections.unmodifiableList(list1);
list1.add("C");
System.out.println(list1);
System.out.println(list2);
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
Question #12
Correct Answer:
B
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
Question #14
Given:
import java.io.*;
public class Tester {
public static void main(String[] args) {
try {
doA();
doB();
} catch (IOException e) {
System.out.print("c");
return;
} finally {
System.out.print("d");
}
System.out.print("e");
}
Given:
@Repeatable(Meals.class)
@Target(ElementType.TYPE)
@interface Meal {
String starter() default "";
String mainCourse();
String dessert() default "";
}
and
@Target(ElementType.TYPE)
public @interface Meals {
Meal[] value();
}
Question #17
Given:
public enum Season {
WINTER('w'), SPRING('s'), SUMMER('h'), FALL('f');
char c;
private Season(char c) {
this.c = c;
}
}
and the code fragment:
public static void main(String[] args) {
Season[] sA = Season.values(); // line n1
}
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:
public class DNAsynth {
int aCount;
int tCount;
int cCount;
int gCount;
int setCCount(int c) {
return c;
}
Correct Answer:
BD
Question #19
Given:
Given:
/proj/msg/messages.properties file:
message=Hello {0}, regards {1}
and
/proj/msg/messages_ja_JP.properties file:
message=こんにちは {0}, しくお願いします {1}
and
/proj/msg/Test.java class:
package msg;
public class Test {
public static void main(String[] args) {
// line 1
System.out.println(message);
}
}
and
and
Question #20
Given:
import java.sql.Timestamp;
public class Test {
public static void main(String[] args) {
Timestamp ts = new Timestamp(1);
}
}
and the commands:
javac Test.java
jdep=summary Test.class
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 -
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.
commons-beanutils-1.9.3.jar
commons-collections4-4.2.jar
(Automatic-Module-Name: org.apache.commons.collections4)
commons-lang3-3.8.1.jar
(Automatic-Module-Name: org.apache.commons.lang3)
commons-text-1.3.jar
(Automatic-Module-Name: org.apache.commons.text)
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
Question #22
Correct Answer:
CE
Question #23
Given:
public class Person {
private String name = "Green";
public void setName(String name) {
String title = "Mr. ";
name = title + name;
}
public String toString() {
return name;
}
}
and
public class Test {
public static void main(String args[]) {
Person p = new Person();
p.setName("Blue");
System.out.println(p);
}
}
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
Question #24
Given:
import java.util.function.BiFunction;
public class Pair<T> {
final BiFunction<T, T, Boolean> validator;
T left = null;
T right = null;
private Pair<T> validator=null;
Pair(BiFunction<T, T, Boolean> v, T x, T y) {
validator = v;
set(x, y);
}
void set(T x, T y) {
if(!validator.apply(x, y)) throw new IllegalArgumentException();
setLeft(x);
setRight(y);
}
void setLeft(T x) {
left = x;
}
void setRight(T y) {
right = y;
}
final boolean isValid() {
return validator.apply(left, right);
}
}
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
Correct Answer:
B
Question #26
Given:
package com.foo;
public class Foo {
static final int A = 0;
public static final int B = 0;
private static final int C = 0;
int d = 0;
protected int e = 0;
public int f = 0;
private int g = 0;
public void foo(int h) {
int i = 0;
}
package com.foo.bar;
public class Bar extends com.foo.Foo {
@Override
public void foo(int j) {
// line 1
}
} (Choose four.)
A. A
e
Most Voted
B. B
f
Most Voted
C. C
A
D. D
j
Most Voted
E. E
d
F. F
c
G. G
i
H. H
B
Most Voted
I. I
h
J. J
g
Correct Answer:
CFHJ
Hide Answer
uestion Discussion5 ChatGPT Statistics
Share
Question #27
C. C
Most Voted
D. D
Correct Answer:
A
Hide Answer
uestion Discussion15 ChatGPT Statistics
Share
Question #28
Correct Answer:
A
Hide Answer
uestion Discussion10 ChatGPT Statistics
Share
Question #29
Given:
public interface Rectangle {
default double calculateSurfaceArea(double l, double w) {
return l * w;
}
}
Correct Answer:
B
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:
String testName = "smith";
int testMembershipLength = 5;
long matches = clubMembers
.peek(new Consumer<Member>() {
@Override
public void accept(Member m) {
m.print();
}
})
.filter(m -> m.getYearsMembership() >= testMembershipLength)
.map(m -> testName.compareToIgnoreCase(m))
.filter(a -> a > 0)
.count();
System.out.println(matches);
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
Correct Answer:
A
Hide Answer
uestion Discussion5 ChatGPT Statistics
Share
Question #33
Given:
public class Main {
public static void main(String[] args) {
List<String> fruits = List.of("banana", "orange", "apple", "lemon");
Stream<String> s1 = fruits.stream();
Stream<String> s2 = s1.peek(i -> System.out.print(i + " "));
System.out.println("---");
Stream<String> s3 = s2.sorted();
Stream<String> s4 = s3.peek(i -> System.out.print(i + " "));
System.out.println("---");
String strFruits = s4.collect(Collectors.joining(","));
}
}
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
Correct Answer:
C
Hide Answer
uestion Discussion4 ChatGPT Statistics
Share
Question #35
Given:
import java.util.List;
import java.util.Optional;
System.out.println(item.orElseThrow());
}
}
class Item {
public String name;
public int amount;
@Override
public String toString() {
return "Name: " + name + ", Amount: " + amount;
}
}
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:
public class Main {
public static void main(String[] args) {
String[] furnitures = {"Door", "Window", "Chair"};
var sb = new StringBuilder();
for (var i = 0; i < furnitures.length; i++) {
var index = i + 1;
sb.append(index);
sb.append(")");
sb.append(furnitures[i].charAt(i));
sb.append(" ");
if (index < furnitures.length) {
sb.append(" ");
}
}
Correct Answer:
A
Hide Answer
uestion Discussion5 ChatGPT Statistics
Share
Question #37
Given:
public class Tester {
public static int reduce(int x) {
int y = 4;
class Computer {
int reduce(int x) {
return x - y--;
}
}
Computer a = new Computer();
return a.reduce(x);
}
Correct Answer:
D
Hide Answer
uestion Discussion7 ChatGPT Statistics
Share
Question #38
Correct Answer:
DE
Hide Answer
uestion Discussion4 ChatGPT Statistics
Share
Question #39
Correct Answer:
D
Hide Answer
uestion Discussion9 ChatGPT Statistics
Share
Question #40
Correct Answer:
E
Question #41
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:
public interface APIInterface (
and
public default void process() (System.out.println ("Process() called 1."); }
public abstract class AbstractAPI {
and
public abstract void process();}
public class Api Impl extends AbstractAPI implements APIInterface {
public void process();
}
}}
Correct Answer:
E
Hide Answer
uestion Discussion29 ChatGPT Statistics
Share
Question #44
Given:
interface MyInterface1 {
public int method() throws Exception;
private void pMethod() { /* an implementation of pMethod */ }
}
interface MyInterface2 {
public static void sMethod() { /* an implementation of sMethod */ }
private boolean equals();
}
interface MyInterface3 {
public void method();
}
interface MyInterface4 {
public void method(String str);
}
interface MyInterface5 {
public static void sMethod();
public void method(String str);
}
Correct Answer:
DE
Hide Answer
uestion Discussion11 ChatGPT Statistics
Question #45
Given:
class Super {
static String greeting() { return "Good Night"; }
String name() { return "Harry"; }
}
class Test {
public static void main(String[] args) {
Super s = new Sub();
System.out.println(s.greeting() + ", " + s.name());
}
}
B.
Correct Answer:
B
Question #46
Question #46
Correct Answer:
A
Hide Answer
uestion Discussion7 ChatGPT Statistics
Share
Question #47
Given:
Given:
class Super {
final int num; // line n1
public Super(int num) {
this.num = num;
}
final void method() {
System.out.println("Output from Super");
}
}
class Sub extends Super {
int num; // line n2
Sub(short num) { // line n3
super(num);
}
protected void method() { // line n4
System.out.println("Output from Sub");
}
}
line n3
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
Correct Answer:
A
Hide Answer
uestion Discussion7 ChatGPT Statistics
Share
Question #49
Given:
public class ExSuper extends Exception {
private final int eCode;
public ExSuper(int eCode, Throwable cause) {
super(cause);
this.eCode = eCode;
}
Correct Answer:
D
Hide Answer
uestion Discussion8 ChatGPT Statistics
Share
Question #50
Correct Answer:
AC -
Question #51
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:
Given:
and
Hide Answer
uestion Discussion7 ChatGPT Statistics
Share
Question #53
Given:
class Scope {
static int myint=666;
public static void main(String[] args) {
int myint = myint;
System.out.println(myint);
}
}
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:
package test.t1;
public class A {
public int x = 42; // line 1
protected A() {}
}
and
package test.t2;
import test.t1.*;
public class B extends A { // line 2
int x = 17; // line 3
public B() { super(); }
}
and
package test;
import test.t1.*;
import test.t2.*;
public class Tester {
public static void main(String[] args) { // line 4
A obj = new B(); // line 5
System.out.println(obj.x); // line 5
}
}
and
and
Correct Answer:
G
Hide Answer
uestion Discussion9 ChatGPT Statistics
Share
Question #55
Given:
// line 1
var fruits = List.of("apple", "orange", "banana", "lemon");
fruits.forEach(function);
Correct Answer:
D
Question #56
Given:
public class Option {
public static void main(String[] args) {
System.out.println("Ans : " + convert("a").get());
}
Most Voted
Correct Answer:
A
Hide Answer
uestion Discussion13 ChatGPT Statistics
Share
Question #57
Given:
@JsonField(type=JsonField.Type.INT)
private int x;
@JsonField(type=JsonField.Type.INT)
private int y;
}
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:
class SomeClass {
public void methodA() {
System.out.println("SomeClass#methodA()");
}
}
Correct Answer:
B
Hide Answer
uestion Discussion5 ChatGPT Statistics
Share
Question #59
Given:
public interface A {
public Iterable a();
}
public interface B extends A {
public Collection a();
}
public interface C extends A {
public Path a();
}
public interface D extends B, C {
}
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:
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
Question #61
Given:
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:
Correct Answer:
B
Hide Answer
uestion Discussion5 ChatGPT Statistics
Share
Question #63
Given:
var fruits = List.of("apple", "orange", "banana", "lemon");
Optional<String> result = fruits.stream().filter(e -> e.contains("n")).findAny(); // line 1
System.out.println(result.get());
Correct Answer:
D
Hide Answer
uestion Discussion7 ChatGPT Statistics
Share
Question #64
class MyPersistenceData {
String str;
private void methodA() {
System.out.println("methodA");
}
}
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:
public class Foo {
public void foo(Collection arg) {
System.out.println("Bonjour le monde!");
}
}
and
and
Correct Answer:
A, C, I
Question #66
Correct Answer:
E
Hide Answer
uestion Discussion14 ChatGPT Statistics
Share
Question #67
System.out.println(Alphabet.getFirstLetter());
Correct Answer:
D
Hide Answer
uestion Discussion10 ChatGPT Statistics
Share
Question #68
Correct Answer:
D
Hide Answer
uestion Discussion11 ChatGPT Statistics
Share
Question #69
@inteface Resource {
String[] value();
}
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
Question #71
Given:
Correct Answer:
B
Hide Answer
uestion Discussion11 ChatGPT Statistics
Share
Question #72
Correct Answer:
B
Hide Answer
uestion Discussion5 ChatGPT Statistics
Share
Question #73
C-
C++
Java -
Go -
Kotlin -
and
String fileName = "lines.txt";
List<String> list = new ArrayList<>();
try (Stream<String> stream = Files.lines(Paths.get(fileName))) {
list = stream
.filter(line -> line.equalsIgnoreCase("JAVA"))
.map(String::toUpperCase)
.collect(Collectors.toList());
} catch (IOException e) {
e.printStackTrace();
}
list.forEach(System.out::println);
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:
Correct Answer:
C
Hide Answer
uestion Discussion4 ChatGPT Statistics
Share
Question #75
Given:
Correct Answer:
C
Question #76
Given:
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:
StringBuilder foo(StringBuilder s) {
System.out.print(s + " oh " + sb2);
return new StringBuilder("ey");
}
}
Correct Answer:
E
Hide Answer
uestion Discussion2 ChatGPT Statistics
Share
Question #78
Correct Answer:
A
Hide Answer
uestion Discussion6 ChatGPT Statistics
Share
Question #79
Integer i = 11;
Correct Answer:
AB
Question #80
Given:
interface AbilityA {
default void action() {
System.out.println("a action");
}
}
and
interface AbilityB {
void action();
}
Correct Answer:
E
Question #81
Given:
public class A {
int a = 0;
int b = 0;
int c = 0;
public void foo(int i) {
a += b * i;
c = b * i;
}
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.
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:
1. interface Pastry {
2. void getIngredients();
3. }
4. abstract class Cookie implements Pastry {}
5. class ChocolateCookie implements Cookie {
6. public void getIngredients() {}
7. }
8. class CoconutChocolateCookie extends ChocolateCookie {
9. void getIngredients(int x) {}
10. }
Correct Answer:
ACEF
Question #86
Given:
public class Employee {
private String name;
private String neighborhood;
private int salary;
// Constructors and setter and getter methods go here
}
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
Question #87
Given:
Given:
import java.util.ArrayList;
import java.util.Arrays;
public class NewMain {
public static void main(String[] args) {
String[] catNames = {"abyssinian", "oxicat",
"korat", "laperm", "bengal", "sphynx"};
var cats = new ArrayList<>(Arrays.asList(catNames));
cats.sort((var a, var b) -> -a.compareTo(b));
cats.forEach(System.out::println);
}
}
Correct Answer:
C
Hide Answer
uestion Discussion8 ChatGPT Statistics
Share
Question #88
Given:
Correct Answer:
B
Hide Answer
uestion Discussion5 ChatGPT Statistics
Share
Question #89
Given:
public class Person {
private String name;
private Person child;
public Person(String name, Person child) {
this(name);
this.child = child;
}
public Person(String name) {
this.name = name;
}
public String toString() {
return name + " child";
}
}
and
Correct Answer:
A
Hide Answer
uestion Discussion1 ChatGPT Statistics
Share
Question #90
Given:
public class X {
protected void print(Object obj) {
System.out.println(obj);
}
Correct Answer:
D
Question #91
Given:
Correct Answer:
A
Hide Answer
uestion Discussion4 ChatGPT Statistics
Share
Question #92
var i = 1;
var result = IntStream.generate(() -> { return i; })
.limit(100).sum();
System.out.println(result);
Correct Answer:
BD
Hide Answer
uestion Discussion7 ChatGPT Statistics
Share
Question #93
Given:
int i = 3;
int j = 25;
System.out.println(i > 2 ? i > 10 ? 1 * (j + 10) : 1 * j + 5 : i);
Correct Answer:
A
Hide Answer
uestion Discussion2 ChatGPT Statistics
Share
Question #94
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:
public interface A {
abstract void x();
public default void y() { }
}
and
Correct Answer:
A
Hide Answer
uestion Discussion3 ChatGPT Statistics
Share
Question #97
Given:
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:
public class X {
private Collection collection;
public void set(Collection collection) {
this.collection = collection;
}
and
Correct Answer:
CE
Hide Answer
uestion Discussion3 ChatGPT Statistics
Share
Question #99
int x = 0;
do {
x++;
if (x == 1) {
continue;
}
System.out.println(x);
} while (x < 1);
Correct Answer:
D
Hide Answer
uestion Discussion2 ChatGPT Statistics
Share
Question #100
Given TripleThis.java:
import java.util.function.*;
public class TripleThis {
public static void main(String[] args) {
Function<Integer, Integer> tripler = x -> { return (Integer) x * 3; };
TripleThis.printValue(tripler, 4);
}
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
Correct Answer:
B
Hide Answer
uestion Discussion2 ChatGPT Statistics
Share
Question #102
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
Correct Answer:
B
Hide Answer
uestion Discussion3 ChatGPT Statistics
Share
Question #104
Given:
Automobile.java -
public abstract class Automobile { // line 1
abstract void wheels();
}
// Car.java
public class Car extends Automobile { // line 2
void wheels(int i) { // line 3
System.out.print(4);
}
Hide Answer
uestion Discussion3 ChatGPT Statistics
Share
Question #105
Correct Answer:
A