0% found this document useful (0 votes)
9 views10 pages

Ultra

The document contains a set of practice questions related to Java programming concepts, including collections, exception handling, and interfaces. Each question is unmarked and requires the participant to select or explain answers based on Java principles. The document also includes submission details and indicates that correct answers will be available after all marks are posted.

Uploaded by

hadjidjanys
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

Ultra

The document contains a set of practice questions related to Java programming concepts, including collections, exception handling, and interfaces. Each question is unmarked and requires the participant to select or explain answers based on Java principles. The document also includes submission details and indicates that correct answers will be available after all marks are posted.

Uploaded by

hadjidjanys
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Practice Questions

Practice Questions

ANYS HADJIDJ
Your instructor has overridden the calculated test mark

Final Mark
Submitted 15/11/2024, 05:46 (GMT)

0 / 25

Correct answers appear after all marks have been posted

Question scores appear after all marks have been posted

Assignment Content

Question 1 Not marked

When executed, what is the output of the following code?

https://blackboard.staffs.ac.uk/ultra/courses/_89236_1/grade nId=_657281_1&contentId=_6381493_1&courseId=_89236_1 15/11/2024 06 08


Page 1 sur 10
:
s
A true

B A compiler error

C false

Question 2 Not marked

What is the primary difference between a HashSet and a TreeSet in Java?

A HashSet allows null values, while TreeSet does not

B HashSet allows duplicate elements, TreeSet while does not

https://blackboard.staffs.ac.uk/ultra/courses/_89236_1/grade nId=_657281_1&contentId=_6381493_1&courseId=_89236_1 15/11/2024 06 08


Page 2 sur 10
:
s
TreeSet sorts its elements in natural order, while HashSet does not maintain any
C
specific order

D TreeSet allows duplicate elements, while HashSet does not

Question 3 Not marked

Explain the difference between a referential check and an equality check in Java. Your answer
should describe how each type of check is performed and what it is used for.

Your Answer

Question 4 Not marked

Which of the following are characteristics of abstract classes in Java?

A An abstract class cannot be instantiated directly

B An abstract class must have at least one abstract method

C An abstract class can implement multiple interfaces

D An abstract class can contain non-abstract (concrete) methods

Question 5 Not marked

Which of the following is true about a constructor?

https://blackboard.staffs.ac.uk/ultra/courses/_89236_1/grade nId=_657281_1&contentId=_6381493_1&courseId=_89236_1 15/11/2024 06 08


Page 3 sur 10
:
s
It has the same name as the class, but must start with a lower case letter to respect
A the Camel-case
naming convention.

B It is mandatory to define at least one explicit (manually coded) constructor in a class.

C It has no return type.

D It has a void return type.

Question 6 Not marked

Which of the following Java collections would you use if you need a collection that does not
allow duplicate elements and maintains elements in insertion order?

A TreeSet

B ArrayList

C LinkedHashSet

D HashSet

Question 7 Not marked

In the following code snippet there is a missing line where a HashMap is initialised and a key-
value pair is added.

Choose the correct code that would complete the snippet and allow it to print the value
associated with the key "name".

https://blackboard.staffs.ac.uk/ultra/courses/_89236_1/grade nId=_657281_1&contentId=_6381493_1&courseId=_89236_1 15/11/2024 06 08


Page 4 sur 10
:
s
HashMap<String, String> map = new HashMap<>();
A
map.put("name", "Alice");

HashMap map = new HashMap();


B
map.put("name", "Alice");

HashMap<String, String> map = new HashMap<String, String>();


C
map.add("name", "Alice");

HashMap<String, String> map = new HashMap<>();


D
map.put("Alice", "name");

Question 8 Not marked

When using try/catch blocks, it is optional to have a parameter in a catch block.

A False

B True

Question 9 Not marked

https://blackboard.staffs.ac.uk/ultra/courses/_89236_1/grade nId=_657281_1&contentId=_6381493_1&courseId=_89236_1 15/11/2024 06 08


Page 5 sur 10
:
s
After one or more try/catch blocks, it is mandatory to have a finally block?

A True

B False

Question 10 Not marked

Which statement about Java HashMap is true?

A HashMap allows one null key and multiple null values

B HashMap allows duplicate keys

C HashMap maintains the order of elements based on their insertion order

D HashMap automatically sorts its entries by key

Question 11 Not marked

When executed, what does the following code output?

https://blackboard.staffs.ac.uk/ultra/courses/_89236_1/grade nId=_657281_1&contentId=_6381493_1&courseId=_89236_1 15/11/2024 06 08


Page 6 sur 10
:
s
ArithmeticException
A This is the finally block
Array out of bounds!

B A compiler error

ArithmeticException
This is the finally block
C
Array out of bounds!
Out of the block

ArithmeticException
D
Array out of bounds!

ArithmeticException
E
This is the finally block

Question 12 Not marked

https://blackboard.staffs.ac.uk/ultra/courses/_89236_1/grade nId=_657281_1&contentId=_6381493_1&courseId=_89236_1 15/11/2024 06 08


Page 7 sur 10
:
s
Consider the following Java code. Is the exception checked or unchecked?

A It depends on the code implementation in riskyMethod()

B Checked exception

C Unchecked exception

D Neither checked nor unchecked; it’s a syntax error

Question 13 Not marked

Which of the following statements is true about Java Interfaces?

A Interfaces can be instantiated directly using the new keyword.

B An interface can contain instance variables

https://blackboard.staffs.ac.uk/ultra/courses/_89236_1/grade nId=_657281_1&contentId=_6381493_1&courseId=_89236_1 15/11/2024 06 08


Page 8 sur 10
:
s
C An interface can inherit multiple interfaces

D All methods in an interface must have a body

Question 14 Not marked

The following code uses the Scanner class to read input from the user. What is the program's
output when the user types in the input "Java"?

A The program will ignore "Java" and prompt the user again.

B The program will output "Invalid input" and exit

C The program will crash with an InputMismatchException

D The program will output You entered: Java

https://blackboard.staffs.ac.uk/ultra/courses/_89236_1/grade nId=_657281_1&contentId=_6381493_1&courseId=_89236_1 15/11/2024 06 08


Page 9 sur 10
:
s
https://blackboard.staffs.ac.uk/ultra/courses/_89236_1/grade nId=_657281_1&contentId=_6381493_1&courseId=_89236_1 15/11/2024 06 08
Page 10 sur 10
:
s

You might also like