0% found this document useful (0 votes)
176 views32 pages

Final Exam

Test questions

Uploaded by

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

Final Exam

Test questions

Uploaded by

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

1.

CS 1102-01 - AY2025-T1
2. Final Exam

Final Exam

Question 1
Answer saved

Marked out of 1.00

Flag question

Question text
What is the output of the following code snippet?
int x = 5;
x += ++x + x++;
System.out.println(x);
Question 1Answer
a.
15
b.
16
c.
17
d.
18
Clear my choice

Question 2
Answer saved

Marked out of 1.00

Flag question

Question text
Which of the following methods is used to shuffle the elements of an ArrayList in
Java?
Question 2Answer
a.
shuffle()
b.
mix()
c.
randomize()
d.
Collections.shuffle()
Clear my choice

Question 3
Answer saved

Marked out of 1.00

Flag question

Question text
Which of the following statements about the finally block in exception handling is
true?
Question 3Answer
a.
The finally block is executed only when an exception occurs.
b.
The finally block is executed only when there is no exception.
c.
The finally block is executed regardless of whether an exception occurs or not.
d.
The finally block is optional and can be excluded from the try-catch structure.
Clear my choice

Question 4
Answer saved

Marked out of 1.00


Flag question

Question text
Can a catch block catch multiple types of exceptions in Java?
Question 4Answer
a.
Yes, by separating the exception types with a comma.
b.
Yes, by nesting multiple catch blocks.
c.
No, each catch block can handle only one type of exception.
d.
No, catch blocks are not used to catch exceptions.
Clear my choice

Question 5
Answer saved

Marked out of 1.00

Flag question

Question text
In Java, can an abstract class be instantiated?
Question 5Answer
a.
Yes, an abstract class can be instantiated.
b.
No, an abstract class cannot be instantiated.
c.
It depends on the access modifiers of the abstract class.
d.
It depends on the version of Java being used.
Clear my choice
Question 6
Answer saved

Marked out of 1.00

Flag question

Question text
How does the List interface differ from the Set interface in the Collection Hierarchy?
Question 6Answer
a.
List allows duplicate elements, while Set does not.
b.
List maintains elements in a specific order, while Set does not.
c.
List provides faster lookup operations compared to Set.
d.
List supports concurrent access, while Set does not.
Clear my choice

Question 7
Answer saved

Marked out of 1.00

Flag question

Question text
Which of the following is an advantage of using JavaFX over Swing?
Question 7Answer
a.
Better backward compatibility with older Java versions
b.
Enhanced support for complex layout management
c.
Easier integration with web-based technologies
d.
Improved performance for handling large datasets
Clear my choice

Question 8
Answer saved

Marked out of 1.00

Flag question

Question text
What is the output of the following code snippet?
ArrayList<String> names = new ArrayList<>();
names.add("John");
names.add("Jane");
names.add("John");
System.out.println(names.indexOf("John"));

Question 8Answer
a.
0
b.
1
c.
2
d.
-1
Clear my choice

Question 9
Answer saved

Marked out of 1.00

Flag question
Question text
Which keyword is used to define a block of code that will always be executed,
regardless of whether an exception occurs or not?
Question 9Answer
a.
try
b.
catch
c.
throw
d.
finally
Clear my choice

Question 10
Answer saved

Marked out of 1.00

Flag question

Question text
What is the output of the following code snippet?
ArrayList<String> colors = new ArrayList<>();
colors.add("Red");
colors.add("Blue");
System.out.println(colors.indexOf("Green"));

Question 10Answer
a.
-1
b.
0
c.
1
d.
Error
Clear my choice

Question 11
Answer saved

Marked out of 1.00

Flag question

Question text
When is a static block executed in Java?
Question 11Answer
a.
When an object of the class is created.
b.
When a static method is called.
c.
When the class is loaded into memory.
d.
When a non-static method is called.
Clear my choice

Question 12
Answer saved

Marked out of 1.00

Flag question

Question text
What is the purpose of the Stream API's forEach() method?
Question 12Answer
a.
To apply an action to each element of the stream
b.
To filter the elements of a stream based on a given predicate
c.
To transform the elements of a stream using a mapping function
d.
To perform a reduction operation on the elements of a stream
Clear my choice

Question 13
Answer saved

Marked out of 1.00

Flag question

Question text
How does the Set interface ensure uniqueness of elements?
Question 13Answer
a.
By automatically removing duplicate elements when adding to the set
b.
By comparing elements using their memory addresses
c.
By comparing elements using their hash codes and equals() method
d.
By enforcing immutability on the elements of the set
Clear my choice

Question 14
Answer saved

Marked out of 1.00

Flag question

Question text
Which of the following is NOT a valid way to declare a String variable?
Question 14Answer
a.
String name = "John";
b.
String name = new String("John");
c.
String name;
d.
String name = 'John';
Clear my choice

Question 15
Answer saved

Marked out of 1.00

Flag question

Question text
What is the purpose of the "static" keyword in method parameters in Java?
Question 15Answer
a.
It indicates that the method parameter is optional.
b.
It indicates that the method parameter cannot be modified.
c.
It indicates that the method parameter is shared among all instances of the class.
d.
There is no purpose of using the "static" keyword in method parameters.
Clear my choice

Question 16
Answer saved

Marked out of 1.00

Flag question

Question text
Which JavaFX class is used to create a pagination control?
Question 16Answer
a.
Pagination
b.
PageControl
c.
PagePane
d.
PageSelector
Clear my choice

Question 17
Answer saved

Marked out of 1.00

Flag question

Question text
How does the concept of method overloading contribute to code flexibility and code
readability in object-oriented programming?
Question 17Answer
a.
Method overloading allows for code reuse through inheritance and polymorphism.
b.
Method overloading simplifies complex code structures and reduces code
duplication.
c.
Method overloading allows for dynamic binding of methods at runtime.
d.
Method overloading provides multiple ways to call a method, improving code
readability.
Clear my choice

Question 18
Answer saved

Marked out of 1.00


Flag question

Question text
What is the output of the following code snippet?
int[ ] numbers = new int[5];
System.out.println(numbers.length);

Question 18Answer
a.
0
b.
5
c.
null
d.
ArrayIndexOutOfBoundsException
Clear my choice

Question 19
Answer saved

Marked out of 1.00

Flag question

Question text
Static methods and variables can be accessed without creating an instance of the
class.
Question 19Answer
a.
True
b.
False
Clear my choice

Question 20
Answer saved
Marked out of 1.00

Flag question

Question text
Which of the following is NOT a valid Java operator for performing arithmetic
operations?
Question 20Answer
a.
%
b.
^
c.
*
d.
/
Clear my choice

Question 21
Answer saved

Marked out of 1.00

Flag question

Question text
How can you handle keyboard events in a Java GUI application?
Question 21Answer
a.
By implementing the KeyListener interface
b.
By using the KeyEvent class directly
c.
By registering a KeyAdapter on the JFrame
d.
By overriding the actionPerformed() method
Clear my choice

Question 22
Answer saved

Marked out of 1.00

Flag question

Question text
What happens if an exception is thrown inside a try block and there is no
corresponding catch block to handle it?
Question 22Answer
a.
The program terminates
b.
The exception is ignored and the program continues executing
c.
The exception is caught by the finally block
d.
The exception is propagated up the call stack to the next available catch block
Clear my choice

Question 23
Answer saved

Marked out of 1.00

Flag question

Question text
Which of the following is true regarding the use of "super" keyword in Java?
Question 23Answer
a.
It is used to access static members of a class.
b.
It is used to create an instance of a class.
c.
It is used to call the constructor of the superclass.
d.
It is used to override methods in a superclass.
Clear my choice

Question 24
Answer saved

Marked out of 1.00

Flag question

Question text
Which block is used to specify the code that should always execute, regardless of
whether an exception occurs or not?
Question 24Answer
a.
try
b.
catch
c.
finally
d.
throw
Clear my choice

Question 25
Answer saved

Marked out of 1.00

Flag question

Question text
What will be the output of the following code?
int num = 15;
if (num > 10) {
System.out.println("A");
} else if (num > 5) {
System.out.println("B");
} else {
System.out.println("C");
}
Question 25Answer
a.
A
b.
B
c.
C
d.
None of the above
Clear my choice

Question 26
Answer saved

Marked out of 1.00

Flag question

Question text
What will happen if an exception is thrown but not caught in the code?
Question 26Answer
a.
The program will terminate abruptly with an error message.
b.
The program will ignore the exception and continue execution.
c.
The program will enter an infinite loop.
d.
The program will display a warning message but continue execution.
Clear my choice

Question 27
Answer saved
Marked out of 1.00

Flag question

Question text
What is the output of the following code snippet?
ArrayList<Integer> numbers = new ArrayList<>();
numbers.add(1);
numbers.add(2);
numbers.add(3);
System.out.println(numbers.get(2));

Question 27Answer
a.
1
b.
2
c.
3
d.
Error
Clear my choice

Question 28
Answer saved

Marked out of 1.00

Flag question

Question text
Consider the following code snippet:
public class MyClass {
private static int number = 10;
public static void modifyNumber() {
number *= 2;
}
public static void main(String[] args) {
modifyNumber();
System.out.println(number);
}
}
What will be the output of the code?

Question 28Answer
a.
5
b.
10
c.
20
d.
Compilation error
Clear my choice

Question 29
Answer saved

Marked out of 1.00

Flag question

Question text
How does the Stream API's anyMatch() method behave when encountering a
matching element in the stream?
Question 29Answer
a.
It terminates the stream and returns true.
b.
It terminates the stream and returns false.
c.
It continues processing the remaining elements and returns true.
d.
It continues processing the remaining elements and returns false.
Clear my choice

Question 30
Answer saved

Marked out of 1.00

Flag question

Question text
What is the output of the following code?
interface MyInterface {
default void display() {
System.out.println("MyInterface");
}
}
class MyClass implements MyInterface {
public void display() {
System.out.println("MyClass");
}
}
public class Main {
public static void main(String[] args) {
MyInterface obj = new MyClass();
obj.display();
}
}

Question 30Answer
a.
MyInterface
b.
MyClass
c.
Compilation error
d.
Runtime exception
Clear my choice
Contact site support
You are logged in as Samuel Gono (Log out)
Data retention summary
Get the mobile app
Policies
Switch to the standard theme
Powered by Moodle
Skip to main content

Side panel
UoPeople Time

1There are 1 unread conversations










































Open course index


Open block drawer
1. CS 1102-01 - AY2025-T1
2. Final Exam

Final Exam
Back

Time left 0:38:02


Question 21
Answer saved

Marked out of 1.00

Flag question

Question text
How can you handle keyboard events in a Java GUI application?
Question 21Answer
a.
By implementing the KeyListener interface
b.
By using the KeyEvent class directly
c.
By registering a KeyAdapter on the JFrame
d.
By overriding the actionPerformed() method
Clear my choice

Question 22
Answer saved

Marked out of 1.00

Flag question

Question text
What happens if an exception is thrown inside a try block and there is no
corresponding catch block to handle it?
Question 22Answer
a.
The program terminates
b.
The exception is ignored and the program continues executing
c.
The exception is caught by the finally block
d.
The exception is propagated up the call stack to the next available catch block
Clear my choice

Question 23
Answer saved

Marked out of 1.00

Flag question

Question text
Which of the following is true regarding the use of "super" keyword in Java?
Question 23Answer
a.
It is used to access static members of a class.
b.
It is used to create an instance of a class.
c.
It is used to call the constructor of the superclass.
d.
It is used to override methods in a superclass.
Clear my choice

Question 24
Answer saved

Marked out of 1.00

Flag question

Question text
Which block is used to specify the code that should always execute, regardless of
whether an exception occurs or not?
Question 24Answer
a.
try
b.
catch
c.
finally
d.
throw
Clear my choice

Question 25
Answer saved

Marked out of 1.00

Flag question

Question text
What will be the output of the following code?
int num = 15;
if (num > 10) {
System.out.println("A");
} else if (num > 5) {
System.out.println("B");
} else {
System.out.println("C");
}
Question 25Answer
a.
A
b.
B
c.
C
d.
None of the above
Clear my choice

Question 26
Answer saved

Marked out of 1.00

Flag question
Question text
What will happen if an exception is thrown but not caught in the code?
Question 26Answer
a.
The program will terminate abruptly with an error message.
b.
The program will ignore the exception and continue execution.
c.
The program will enter an infinite loop.
d.
The program will display a warning message but continue execution.
Clear my choice

Question 27
Answer saved

Marked out of 1.00

Flag question

Question text
What is the output of the following code snippet?
ArrayList<Integer> numbers = new ArrayList<>();
numbers.add(1);
numbers.add(2);
numbers.add(3);
System.out.println(numbers.get(2));

Question 27Answer
a.
1
b.
2
c.
3
d.
Error
Clear my choice

Question 28
Answer saved

Marked out of 1.00

Flag question

Question text
Consider the following code snippet:
public class MyClass {
private static int number = 10;
public static void modifyNumber() {
number *= 2;
}
public static void main(String[] args) {
modifyNumber();
System.out.println(number);
}
}
What will be the output of the code?

Question 28Answer
a.
5
b.
10
c.
20
d.
Compilation error
Clear my choice

Question 29
Answer saved

Marked out of 1.00

Flag question

Question text
How does the Stream API's anyMatch() method behave when encountering a
matching element in the stream?
Question 29Answer
a.
It terminates the stream and returns true.
b.
It terminates the stream and returns false.
c.
It continues processing the remaining elements and returns true.
d.
It continues processing the remaining elements and returns false.
Clear my choice

Question 30
Answer saved

Marked out of 1.00

Flag question

Question text
What is the output of the following code?
interface MyInterface {
default void display() {
System.out.println("MyInterface");
}
}
class MyClass implements MyInterface {
public void display() {
System.out.println("MyClass");
}
}
public class Main {
public static void main(String[] args) {
MyInterface obj = new MyClass();
obj.display();
}
}

Question 30Answer
a.
MyInterface
b.
MyClass
c.
Compilation error
d.
Runtime exception
Clear my choice
Contact site support
You are logged in as Samuel Gono (Log out)
Data retention summary
Get the mobile app
Policies
Switch to the standard theme
Powered by Moodle
Skip to main content

Side panel
UoPeople Time
1There are 1 unread conversations










































Open course index


Open block drawer
1. CS 1102-01 - AY2025-T1
2. Final Exam

Final Exam
Back

Time left 0:34:02

Question 31
Answer saved

Marked out of 1.00

Flag question

Question text
Which of the following statements is true about static variables in multithreaded
environments?
Question 31Answer
a.
Static variables are thread-safe and do not require any synchronization.
b.
Static variables can cause data inconsistencies and require proper synchronization
mechanisms.
c.
Static variables can only be accessed by a single thread at a time.
d.
Static variables are automatically synchronized by the JVM.
Clear my choice

Question 32
Answer saved

Marked out of 1.00

Flag question

Question text
Which method of the Set interface is used to remove a specific element from the
set?
Question 32Answer
a.
remove()
b.
delete()
c.
erase()
d.
eliminate()
Clear my choice

Question 33
Answer saved

Marked out of 1.00

Flag question

Question text
In event-driven programming, which term refers to an object that handles events
generated by user interaction?
Question 33Answer
a.
ActionListener
b.
EventDispatcher
c.
EventListener
d.
EventHandler
Clear my choice

Question 34
Answer saved

Marked out of 1.00

Flag question

Question text
What is the purpose of the try block in exception handling?
Question 34Answer
a.
To catch exceptions
b.
To define a block of code that may throw an exception
c.
To handle exceptions that occur in the catch block
d.
To terminate the program
Clear my choice

Question 35
Answer saved

Marked out of 1.00

Flag question

Question text
Which method of the Stream API is used to sort the elements of a stream in a
natural order?
Question 35Answer
a.
sort()
b.
order()
c.
arrange()
d.
organize()
Clear my choice
Contact site support
You are logged in as Samuel Gono (Log out)
Data retention summary
Get the mobile app
Policies
Switch to the standard theme
Powered by Moodle

You might also like