Quiz Space

Java Quiz 2: 23 November 2025 (September 2025 term)

Question 1

+7 marksOne or more correct options

Consider the Java code given below that should print the names of students whose grades are between 70.0 and 90.0 (both inclusive).

java
import java.util.*;
class Student {
String name;
double grade;
public Student(String n, double g) {
name = n;
grade = g;
}
}
public class TestGrades {
public static void main(String[] args) {
List<Student> students = new ArrayList<>();
students.add(new Student("Anu", 85.5));
students.add(new Student("Bindu", 92.0));
students.add(new Student("Hari", 78.0));
students.add(new Student("David", 70.0));
students.add(new Student("Hasan", 65.0));
//CODE BLOCK
}
}

Choose the correct option(s) to fill in place of CODE BLOCK to obtain the right answer.

Select all that apply.

  1. A

    students.stream()
    .map(s -> s.grade >= 70.0 && s.grade <= 90.0)
    .forEach(s -> System.out.println(s.name));

  2. B

    students.stream()
    .filter(s -> s.grade >= 70.0 && s.grade <= 90.0)
    .forEach(s -> System.out.println(s.name));

  3. C

    students.stream()
    .filter(s -> s.grade >= 70.0)
    .filter(s -> s.grade <= 90.0)
    .forEach(s -> System.out.println(s.name));

  4. D

    students.stream()
    .filter(s -> s.grade >= 70.0)
    .map(s -> s.grade <= 90.0)
    .forEach(s -> System.out.println(s.name));

Question 2

+5 marksOne correct option

Consider the code given below.
interface Vehicle {
public abstract double getFuelEfficiency();
}
class Car implements Vehicle, Cloneable {
protected double fuelCapacity;
protected double mileage;
public Car(double fuel, double m) {
fuelCapacity = fuel;
mileage = m;
}
public double getFuelEfficiency() {
return fuelCapacity * mileage;
}
public Car clone() throws CloneNotSupportedException {
return (Car) super.clone();
}
}
class ElectricCar extends Car {
public ElectricCar(double batteryCapacity, double mileage) {
super(batteryCapacity, mileage);
}
public ElectricCar clone() throws CloneNotSupportedException {
return (ElectricCar) super.clone();
}
}
public class VehicleTest {
public static void main(String[] args) {
try {
ElectricCar e1 = new ElectricCar(50, 2);
ElectricCar e2 = e1.clone();
e1.fuelCapacity = 100;
System.out.print(e1.getFuelEfficiency() + e2.getFuelEfficiency());
} catch (CloneNotSupportedException e) {
System.out.println("Cloning not supported");
}
}
}
What will the output be?

  1. A

    200.0

  2. B

    300.0

  3. C

    400.0

  4. D

    Cloning not supported

Question 3

+7 marksOne correct option

Consider the Java code given below.

java
import java.util.*;
public class PalindromeChecker {
public static boolean isPalindrome(String str) {
Stack<Character> s = new Stack<>();
Deque<Character> d = new ArrayDeque<>();
for (char ch : str.toCharArray()) {
s.push(ch);
d.add(ch);
}
// CODE BLOCK
return true;
}
public static void main(String[] args) {
String word1 = "level";
String word2 = "hello";
System.out.println("Is word1 a palindrome? " + isPalindrome(word1));
System.out.println("Is word2 a palindrome? " + isPalindrome(word2));
}
}

Choose the correct option to fill in place of CODE BLOCK so that the output is:

text
Is word1 a palindrome? true
Is word2 a palindrome? false

Please note the following methods from type Stack and Deque:

pop(): Removes the object at the top of this stack and returns it.

poll(): Retrieves and removes the head of this deque, or returns null if empty.

peek(): Retrieves, but does not remove, the head of this deque, or returns null if empty.

  1. A

    while (!s.isEmpty()) {
    if (s.pop().equals(d.peek())) {
    return false;
    }
    }

  2. B

    while (!s.isEmpty()) {
    if (s.pop().equals(d.poll())) {
    return false;
    }
    }

  3. C

    while (!s.isEmpty()) {
    if (!s.pop().equals(d.poll())) {
    return false;
    }
    }

  4. D

    while (!s.isEmpty()) {
    if (!s.pop().equals(d.peek())) {
    return false;
    }
    }

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 23 Nov 2025 paper

The IIT Madras BS Programming Concepts using Java (Java) Quiz 2 paper sat on 23 Nov 2025, in the September 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 23 Nov 2025 at a glance
TermSeptember 2025 term
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions15
Marks100
Duration120 min
MSQ4
MCQ11
Official paperIIT M DIPLOMA AN EXAM QDD2 23 Nov 2025 NEW
Negative markingNo negative marking.
Updated

Same Quiz 2, other subjects

More Java