Menu
Question Index
...

What will be the output of the following program?

public class GenericsWithObjectsDemo {
    public static void main(String args[]) {
        GenericsWithObjects<Double> doubleObject = new GenericsWithObjects<Double>(12.0);
        doubleObject.print();
        GenericsWithObjects<String> stringObject = new GenericsWithObjects<String>("MC");
        stringObject.print();
    }
}
class GenericsWithObjects<T> {
    Object obj;
    GenericsWithObjects(Object obj) {
        this.obj = obj;
    }
    void print() {
        System.out.println(obj);
    }
}


12.0
MC
12.0
12.0
Compilation Error
Runtime Error

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