Menu
Question Index
...

What will be the output of the following program?

public class GenericTypesDifferDemo {
    public static void main(String args[])
    {
        GenericsWithObjects<Integer> integerObject = new GenericsWithObjects<Integer>(12);
        GenericsWithObjects<String> stringObject = new GenericsWithObjects<String>("MeritCampus");
        integerObject = stringObject; // LINE A
        integerObject.print(); // LINE B
    }
}
class GenericsWithObjects<T>
{
    T obj;
    GenericsWithObjects(T obj)
    {
        this.obj = obj;
    }
    void print()
    {
        System.out.println(obj);
    }
}


12
MeritCampus
Compilation Error at LINE A
Compilation Error at LINE B

Doubts

Problems

Topic: Java Generics

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App