Skip to main content

Quiz 2.4: Question types and code

Question 1

Which keyword limits a field to its own class?

Show correct answer

private

Show hint

Think of access modifiers.

Question 2

Which statements about this Java code are true?

List<String> names = List.of("Ada", "Linus");
names.add("Grace");
Show correct answer

List.of returns an immutable list

The add call throws an exception

Question 3

Which method returns the larger of two numbers?

Show correct answer

This one:

int max(int a, int b) {
return a > b ? a : b;
}
Question 4

Which React component shows the count after a click?

Show correct answer

This one:

function Counter() {
const [count, setCount] = useState(0);
return <button onClick={() => setCount(count + 1)}>{count}</button>;
}
Question 5

Name the HTTP method that creates a resource in a REST API.

Show correct answer

POST

Show hint

It is one word in capitals.