Menu
Question Index
...

What will be the output of the following program?

public class IsIn {
    static <T, V extends T> boolean isIn(T x, V[] y)
    {
        for (int i = 0; i < y.length; i++) {
            if(x.equals(y[i]))
                 return true;
        }
        return false;
    }
    public static void main(String args[])
    {
        Integer integerNumber[] = {1, 2, 5, 7};
        if(isIn(5, integerNumber))
        {
            System.out.println("5 is present in the given integer array");
        }
        else
        {
            System.out.println("5 is not present in the given integer array");
        }
        String str[] = {"M", "ER", "IT"};
        if(isIn("IT", str))
        {
            System.out.println("IT is present in the given string array");
        }
        else
        {
            System.out.println("IT is not present in the given string array");
        }

    }
}


5 is not present in the given integer array
IT is not present in the given string array
5 is present in the given integer array
IT is present in the given string array
Compilation Error
Runtime Error

Doubts

Problems

Topic: A Generic Class With Two Type Parameters 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