Question 1
Consider the code given below.
Which of the following is NOT true about the given code?
This program may generate ConcurrentModificationException.
It may generate output:

It may generate output:

It may generate output:


The IIT Madras BS Programming Concepts using Java (Java) End Term paper sat on 21 Dec 2025, in the September 2025 term: 23 questions for 100 marks in 180 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.
Consider the code given below.
Which of the following is NOT true about the given code?
This program may generate ConcurrentModificationException.
It may generate output:

It may generate output:

It may generate output:

Correct answer
This program may generate ConcurrentModificationException.
Consider the code given below.
How many activation records are created on the stack during the execution of the code?
3
4
5
6
Correct answer
6
Consider the Java code given below.
Choose all the options which can be used in place of ARG in LINE 1 so that the code outputs the sum of two coordinates.
—
—
—
—
Correct answers
—
—
Consider the following Java code.
Identify the line/s which has/have errors.
Line 2
Line 7
Line 11
Line 12
Line 18
Correct answers
Line 11
Line 12
Line 18
Consider the Java code given below.
Choose the correct option.
This program generates the output: [Amit, Neha, Sita]
This program generates the output: [Neha, Sita]
This program generates the output: [Ravi]
This program generates the output: [Amit, Ravi]
Correct answer
This program generates the output: [Neha, Sita]
Consider the Java code given below.
What will happen when the button (labelled "Press") is clicked?
The label will change to "Button Pressed'' when the button is clicked
The label remains "Start"
The code throws a runtime error
The button will disappear after clicking
Correct answer
The label will change to "Button Pressed'' when the button is clicked
Consider the Java code given below.
Choose the correct options to be filled in place of CODE SEGMENT so that the label displays the text entered in the text field.

—
—
—
Correct answers

—
Consider the Java code given below.
Which of the following options is/are possible result/s of the above code?




Correct answers


Consider the Java code given below.
Which of the following is/are possible output(s) of the above code?
100
70
50
20
Correct answers
70
50
Assume that the file fruits.txt contains the following lines:
Consider the code given below.
Choose the correct option.
LINE 1 generates IOException.
This program generates the output:

This program generates the output:

This program generates the output:

Correct answer
This program generates the output:

Consider the Java code given below.
What will the output be?




Correct answer

Consider the Java code given below.
What will the output be?
null, null, 0.0
A12345, null, 5000.0
A12345, XYZ, 5000.0
A12345, Rina, 0.0
******, XYZ, 0.0
Correct answer
A12345, null, 5000.0
Method Optional.ofNullable(T value) returns an Optional that describes the specific value, if non-null; otherwise returns an empty Optional. Based on this description, consider the code given below, and answer the given question.
Choose the correct option.
This program generates the output:

This program terminates due to NullPointerException after printing:

This program generates the output:

This program generates the output:

Correct answer
This program generates the output:

Consider the following Java code.
What will the output be?




Correct answer

Consider the Java code given below.
Identify the appropriate statement to fill in the blank at LINE 1, such that the output is:
((Displayable)iter.get_next()).display();
((Book)iter.get_next()).display();
((Library)iter.get_next()).display();
iter.get_next().display();
Correct answer
((Displayable)iter.get_next()).display();
Method merge of interface Map has the following structure and functionality:
If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value. Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result is null. Consider the code given below that uses the merge method to combine two maps, and answer the given question.
Choose the correct option regarding the code.
It generates the output: {Apple=10, Banana=8, Orange=8}
It generates the output: {Apple=10, Banana=-2, Orange=8}
It generates the output: {Banana=-2, Apple=10, Orange=8}
It generates NullPointerException during runtime.
Correct answer
It generates the output: {Apple=10, Banana=-2, Orange=8}
Consider the code given below.
Identify the appropriate function header for function sum, such that the output is 78.0, 33.5.
—

—
—
Correct answers
—
—
Consider the following Java code.
Choose the correct option when the class is executed as: java -ea ShoppingTest
This code generates output: 2600.0
This code generates AssertionError: Item price must be positive
This code generates AssertionError: Adding item exceeds cart limit
This code generates AssertionError: Maximum limit must be positive
Correct answer
This code generates AssertionError: Adding item exceeds cart limit
Consider the following Java code that uses chained exceptions.
Which of following can be the output of this code?




Correct answer

Consider the code given below.
Choose the correct option.
Compilation error at LINE 1 because method printQuality() is not overridden in class EpsonPrinter
Compilation error at LINE 2 because method startPrint() is not overridden in class CanonPrinter
This program generates the output:

This program generates the output:

Correct answer
This program generates the output:

Consider the code given below.
Choose the correct option to fill in place of CODE BLOCK so that the output is:




Correct answer

Consider the Java code given below.
Choose the correct option.
It generates the output as:

Compilation fails because Car and Bike do not override fuel()
Compilation fails because Car and Bike cannot be assigned to Vehicle
It generates the output as:

Correct answer
It generates the output as:

Consider the Java code given below.
What will the output be?




Correct answer
