Quiz Space

Programming Concepts using Java · Quiz 2 · 23 Nov 2025 · September 2025 term

Question 5: Consider the Java code given below. How does class MathUt…

Question 5

+7 marksOne correct option

Consider the Java code given below.

java
public class MathUtils {
public <T> T getFirst(T[] arr) {
// Returns the first element of the array
}
public <T extends Number> double sum(T[] arr) {
// Returns the sum of all elements in the array
}
}

How does class MathUtils look after type erasure?

  1. A

    public class MathUtils {
    public Object getFirst(Object[] arr) {
    // Returns the first element of the array
    }
    public double sum(Object[] arr) {
    // Returns the sum of all elements in the array
    }
    }

  2. B

    public class MathUtils {
    public Object getFirst(Object[] arr) {
    // Returns the first element of the array
    }
    public double sum(Number[] arr) {
    // Returns the sum of all elements in the array
    }
    }

  3. C

    public class MathUtils {
    public T getFirst(T[] arr) {
    // Returns the first element of the array
    }
    public double sum(T[] arr) {
    // Returns the sum of all elements in the array
    }
    }

  4. D

    public class MathUtils {
    public Object getFirst(Object[] arr) {
    // Returns the first element of the array
    }
    public double sum(Double[] arr) {
    // Returns the sum of all elements in the array
    }
    }

Show answer

Correct answer

  • B

    public class MathUtils {
    public Object getFirst(Object[] arr) {
    // Returns the first element of the array
    }
    public double sum(Number[] arr) {
    // Returns the sum of all elements in the array
    }
    }

Question 5 of 15 in the IIT Madras BS Programming Concepts using Java (Java) Quiz 2 paper sat on 23 Nov 2025, in the September 2025 term (IIT M DIPLOMA AN EXAM QDD2 23 Nov 2025 NEW). It carries 7 marks.

More questions from this paper

  1. Q1Consider the Java code given below that should print the names of students whose grades are between 70.0 and 90.0 (both…
  2. Q2Consider the code given below.\ interface Vehicle {\ public abstract double getFuelEfficiency();\ }\ class Car implemen…
  3. Q3Consider the Java code given below. Choose the correct option to fill in place of CODE BLOCK so that the output is: Ple…
  4. Q4Consider the following Java code. What will the output be?
  5. Q6Consider the Java code given below.\ interface Discount{\ public void apply(int price);\ }\ class ShoppingCart{\ public…
  6. Q7Consider two Java files located in two different packages as shown below.\ Account.java:\ package com.bank;\ public cla…
  7. Q8Consider the Java code given below.\ interface Shape {\ void draw();\ }\ class ShapeFactory {\ private String type;\ pu…
  8. Q9The merge(K key, V value, remappingFunction) function is defined as: If the specified key is not already associated wit…
  9. Q10Consider the Java code given below that prints the average rating of a set of Rateable objects. From among the options,…
  10. Q11Consider the code given below. Identify the appropriate option(s) to fill in the blank at LINE 1 such that the output o…
  11. Q12Consider the Java code given below.\ class Student {\ private int marks;\ public Student(int marks){\ assert marks >= 0…
  12. Q13Consider the Java code given below. Choose the correct option.
  13. Q14Consider the Java code given below.\ interface Chargeable {\ void showChargeStatus();\ }\ class Laptop implements Charg…
  14. Q15Consider the Java code given below.\ class NegativeBalanceException extends Exception {\ public NegativeBalanceExceptio…