Quiz Space

Java Quiz 2: 16 March 2025 (January 2025 term)

Question 1

+6 marksOne or more correct options

Consider the Java code given below that prints the maximum element of a set. From among the options, identify the appropriate function header for function findMax that takes as input a set of numbers and prints the maximum element of the set.

java
import java.util.*;
class Test {
// FUNCTION HEADER for function findMax
{
// Prints the maximum element of the set
}
public static void main(String[] args) {
Set<Integer> s = new HashSet<>();
s.add(12);
s.add(23);
Set<Double> s1 = new HashSet<>();
s1.add(12.2);
s1.add(23.4);
findMax(s);
findMax(s1);
}
}

Choose the correct option(s)

Select all that apply.

  1. A
  2. B
  3. C
  4. D

Question 2

+6 marksOne correct option

Consider the Java code given below.

java
interface Deliverable {
public static void status() {
System.out.println("Delivery status");
}
public default void deliver() {
System.out.println("Order delivered");
}
}
interface Trackable {
public static void status() {
System.out.println("Tracking status");
}
public default void track() {
System.out.println("Tracking order");
}
}
class FoodOrder implements Deliverable, Trackable {
public void deliver() {
System.out.println("Delivered successfully");
}
}
public class Test {
public static void main(String[] args) {
Deliverable o1 = new FoodOrder();
o1.deliver();
o1.track();
Deliverable.status(); //LINE-1
Trackable.status(); //LINE-2
}
}

Choose the correct option.

  1. A
  2. B
  3. C
  4. D

Question 3

+6 marksOne correct option

The following code maps a set of patients to the number of visits they have made to a hospital and categorizes the patients based on whether they are regular visitors (more than 3 visits) or occasional visitors.

java
import java.util.*;
public class Hospital {
TreeSet<String> rPatients = new TreeSet<String>();
TreeSet<String> oPatients = new TreeSet<String>();
public boolean check(int visits) {
return visits > 3;
}
public void categorizePatients(HashMap<String, Integer> pMap) {
for (Map.Entry<String, Integer> entry : pMap.entrySet()) {
if (check(entry.getValue())) {
rPatients.add(entry.getKey());
} else {
oPatients.add(entry.getKey());
}
}
}
public void displayPatients() {
System.out.println("R Patients: " + rPatients);
System.out.println("O Patients: " + oPatients);
}
public static void main(String[] args) {
HashMap<String, Integer> pMap = new HashMap<String, Integer>();
pMap.put("James", 5);
pMap.put("Ram", 2);
pMap.put("Aisha", 4);
pMap.put("Tanya", 1);
pMap.put("Iva", 3);
Hospital hospital = new Hospital();
hospital.categorizePatients(pMap);
hospital.displayPatients();
}
}

Choose the correct option.

  1. A
  2. B
  3. C
  4. D

12 more questions in this paper

Sign in with Google — it is free — to see every question with its answer and explanation, practise it in learning mode, or take it as a timed mock test.

More on the Java Quiz 2 16 Mar 2025 paper

The IIT Madras BS Programming Concepts using Java (Java) Quiz 2 paper sat on 16 Mar 2025, in the January 2025 term: 15 questions for 100 marks in 120 minutes. The first 3 questions are below. Sign in with Google — it is free — to see the whole paper with its answers and explanations, in learning mode or as a timed mock test.

FeatureJava Quiz 2 16 Mar 2025 at a glance
TermJanuary 2025 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions15
Marks100
Duration120 min
MSQ3
MCQ12
Official paperIIT M DIPLOMA AN EXAM QDD2 16 Mar 2025
Negative markingNo negative marking.
Updated

Same Quiz 2, other subjects

More Java