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);
        obj1.showType();
        NonGeneric obj2 = new NonGeneric("MeritCampus");
        obj2.showType();
    }
}
class NonGeneric
{
    Object ob;
    NonGeneric(Object ob)
    {
        this.ob = ob;
    }
    void showType()
    {
        System.out.println("Type is : "+ob.getClass().getName());
    }
}


Type is : 88
Type is : MeritCampus
Type is : java.lang.Integer
Type is : java.lang.String
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