Question 1 Incorrect
Which are valid keywords in a Java module descriptor (module-infoJava)?
provides, employs
imports, exports
consumes, supplies
requires, exports
Correct answer: requires, exports
Question 2 Incorrect
Which type of variable keeps a constant value once it is assigned?
non-static
static
final
private
Correct answer: final
Question 3 Incorrect
How does the keyword _volatile_ affect how a variable is handled?
It will be read by only one thread at a time.
It will be stored on the hard drive.
It will never be cached by the CPU.
It will be preferentially garbage collected.
Correct answer: It will never be cached by the CPU.
Question 4 Correct
What is the result of this code?
char smooch = 'x';
[Link]((int) smooch);
an alphanumeric character
a negative number
a positive number
a ClassCastException
Question 5 Correct
You get a NullPointerException. What is the most likely cause?
A file that needs to be opened cannot be found.
A network connection has been lost in the middle of communications.
Your code has used up all available memory.
The object you are using has not been instantiated.
Question 6 Incorrect
How would you fix this code so that it compiles?
public class Nosey {
int age;
public static void main(String[] args) {
[Link]("Your age is: " + age);
}
}
Make age static.
Make age global.
Make age public.
Initialize age to a number.
Correct answer: Make age static.
Question 7 Correct
Add a Duck called "Waddles" to the ArrayList ducks.
public class Duck {
private String name;
Duck(String name) {}
}
Duck waddles = new Duck(); [Link](waddles);
Duck duck = new Duck("Waddles"); [Link](waddles);
[Link](new Duck("Waddles"));
[Link](new Waddles());
Question 8 Incorrect
If you encounter UnsupportedClassVersionError it means the code was **\_** on a newer version of
Java than the JRE **\_** it.
executed; interpreting
executed; compiling
compiled; executing
compiled, translating
Correct answer: compiled; executing
Question 9 Incorrect
Given this class, how would you make the code compile?
public class TheClass {
private final int x;
}
A-
public TheClass() {
x += 77;
}
B-
public TheClass() {
x = null;
}
C-
public TheClass() {
x = 77;
}
D-
private void setX(int x) {
this.x = x;
}
public TheClass() {
setX(77);
}
Correct answer: D
Question 10 Correct
How many times f will be printed?
public class Solution {
public static void main(String[] args) {
for (int i = 44; i > 40; i--) {
[Link]("f");
}
}
}
A Runtime exception will be thrown
Question 11 Correct
Which statements about abstract classes are true?
1. They can be instantiated.
2. They allow member variables and methods to be inherited by subclasses.
3. They can contain constructors.
1, 2, and 3
only 3
2 and 3
only 2
Question 12 Incorrect
Which keyword lets you call the constructor of a parent class?
parent
super
this
new
Correct answer: super
Question 13 Incorrect
What is the result of this code?
1: int a = 1;
2: int b = 0;
3: int c = a/b;
4: [Link](c);
It will throw an ArithmeticException.
It will run and output 0.
It will not compile because of line 3.
It will run and output infinity.
Correct answer: It will throw an ArithmeticException.
Question 14 Incorrect
Normally, to access a static member of a class such as [Link], you would need to specify the class
"Math". What would be the best way to allow you to use simply "PI" in your code?
Add a static import.
Declare local copies of the constant in your code.
This cannot be done. You must always qualify references to static members with the class form
which they came from.
Put the static members in an interface and inherit from that interface.
Correct answer: Add a static import.
Question 15 Incorrect
Which keyword lets you use an interface?
extends
implements
inherits
import
Correct answer: implements
Question 16 Incorrect
Why are ArrayLists better than arrays?
You don't have to decide the size of an ArrayList when you first make it.
You can put more items into an ArrayList than into an array.
ArrayLists can hold more kinds of objects than arrays.
You don't have to decide the type of an ArrayList when you first make it.
Correct answer: You don't have to decide the size of an ArrayList when you first make it.
Question 17 Incorrect
Declare a variable that holds the first four digits of Π
int pi = 3.141;
decimal pi = 3.141;
double pi = 3.141;
float pi = 3.141;
Correct answer: float pi = 3.141;
Question 18 Incorrect
Use the magic power to cast a spell
public class MagicPower {
void castSpell(String spell) {}
}
new MagicPower().castSpell("expecto patronum")
MagicPower magicPower = new MagicPower(); [Link]();
[Link]("expelliarmus");
new [Link]();
Correct answer: new MagicPower().castSpell("expecto patronum")
Question 19 Incorrect
What language construct serves as a blueprint containing an object's properties and functionality?
constructor
instance
class
method
Correct answer: class
Question 20 Incorrect
What does this code print?
public static void main(String[] args) {
int x=5,y=10;
swapsies(x,y);
[Link](x+"="+y);
}
static void swapsies(int a, int b) {
int temp=a;
a=b;
b=temp;
}
10=10
5=10
10=5
5=5
Correct answer: 5=10
Question 21 Correct
What is the result of this code?
try {
[Link]("Hello World");
} catch (Exception e) {
[Link]("e");
} catch (ArithmeticException e) {
[Link]("e");
} finally {
[Link]("!");
}
Hello World
It will not compile because the second catch statement is unreachable
Hello World!
It will throw runtime exception
Question 22 Incorrect
What is not a java keyword
finally
native
interface
unsigned
Correct answer: unsigned
Question 23 Incorrect
Which operator would you use to find the remainder after division?
//
DIV
Correct answer: %
Question 24 Correct
Which choice is a disadvantage of inheritance?
Overridden methods of the parent class cannot be reused.
Responsibilities are not evenly distributed between parent and child classes.
Classes related by inheritance are tightly coupled to each other.
The internal state of the parent class is accessible to its children.
Question 25 Incorrect
Declare and initialize an array of 10 ints.
Array<Integer> numbers = new Array<Integer>(10);
Array[int] numbers = new Array[int](10);
int[] numbers = new int[10];
int numbers[] = int[10];
Correct answer: int[] numbers = new int[10];
Question 26 Incorrect
Refactor this event handler to a lambda expression:
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
[Link]("Press me one more time..");
}
});
[Link](ActionListener listener -> [Link]("Press me one
more time..."));
[Link]((event) -> [Link]("Press me one more time..."));
[Link](new ActionListener(ActionEvent e) {() ->
[Link]("Press me one more time...");});
[Link](() -> [Link]("Press me one more time..."));
Correct answer: [Link]((event) -> [Link]("Press me one
more time..."));
Question 27 Incorrect
Which functional interfaces does Java provide to serve as data types for lambda expressions?
Observer, Observable
Collector, Builder
Filter, Map, Reduce
Consumer, Predicate, Supplier
Correct answer: Consumer, Predicate, Supplier