10 free sample questions from a bank of 237, with the correct answers and explanations. No signup required — start practising right now.
1Given: What is the result?
2-4
0-6
1-5
2-4
1-5
1-5
2-4
The compilation fails due to an error in line 1.
0-6
0-6
2-4
Answer: C
2Given 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.)
Replace line 12 with public static void printValue(Function f, int num) {
Replace line 12 with public static void printValue(Function f, T num) {
Replace line 9 with Function tripler = x —> { return (Integer) x * 3; }
Replace line 12 with public static void printValue(Function f, Integer num) {
Replace line 9 with Function tripler = x -> { return x * 3; }
Replace line 9 with Function tripler = x -> [ return x * 3; ]
Answer: A, D
3Given the code fragment: What change on line 1 will make this code compile?
Add catch(M | L e)
Add catch(L e)
Add catch(N | L | M e)
Add catch(L | N e)
Add catch(L | M | N e)
Answer: B
4Given the code fragment: Which two code snippets inserted independently inside println method print Mondial:domainmodel? (Choose two.)
Main.prefix + Main.name
prefix + getName
Main.prefix + Main.getName()
new Main().prefix + new Main().name
prefix + name
prefix + Main.name
Answer: C, D
5Given the code fragment: What is the result?
[Lettuce, Kale]
A compilation error is thrown.
[Lettuce, Kale]
[Seabass, Salmon]
[Kale, Lettuce]
[Salmon, Seabass]
Answer: C
6Given:
Automobile.java - Car.java - What must you do so that the code prints 4?
Remove the parameter from wheels method in line 3.
Remove abstract keyword in line 1.
Replace the code in line 2 with Car ob = new Car();.
Add @Override annotation at line 2.
Answer: A
7Which module is required for any application using Swing or AWT?
java.desktop
java.prefs
java.se
java.logging
java.rmi
Answer: A
8Which set of commands is necessary to create and run a custom runtime image from Java source files?
java,jdeps
javac,jlink
javac,jar
jar,jlink
Answer: B
9Given the code fragment: Which would cause s to be AQCD?
s.replace(s.indexOf("B"), s.indexOf("B"), "Q");
s.replace(s.indexOf("A"), s.indexOf("B"), "Q");
s.replace(s.indexOf("B"), s.indexOf("C"), "Q");
s.replace(s.indexOf("A"), s.indexOf("C"), "Q");
Answer: C
10Given: Which two methods facilitate valid ways to read instance fields? (Choose two.)