Menu
Question Index
...

What will be the output?

public class MinDemo {
    public static void main(String args[])
    {
        Integer[] integerArray ={10, 1, 5, 7};
        Myclass<Integer> integers = new Myclass<Integer>(integerArray);
        System.out.println(integers.min());
    }
}
interface Min<T>
{
    T min();
}
class Myclass<T extends Comparable<T>> implements Min<T>
{
    T[] values;
    Myclass(T[] values)
    {
        this.values = values;
    }
    
    public T min() {
        T min = values[0];
        for (int i = 1; i < values.length; i++)
        {
            if(values[i].compareTo(min)< 0)
            {
                min = values[i];
            }
        }
        return min;
    }
}


1
10
Compilation Error
Runtime Error

Doubts

Problems

Topic: Generic Interface In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App