Menu
Question Index
...

What will be the output of the following program?

public class GenericTypeSafetyDemo {
    public static void main(String args[])
    {
        NonGeneric obj1 = new NonGeneric(88);
        NonGeneric obj2 = new NonGeneric("MeritCampus");
        obj1 = obj2;
        int value = (Integer)obj1.getOb();
        System.out.println(value);
    }
}
class NonGeneric
{
    Object ob;
    NonGeneric(Object ob)
    {
        this.ob = ob;
    }
    Object getOb()
    {
        return ob;
    }
}


88
MeritCampus
Some Other Output
Compilation Error
Runtime Error

Doubts

Problems

Topic: How Generics Improve Type Safety 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