Menu
Question Index
...

What will be the output of the following program?

public class GenericsDemo {
    public static void main(String[] args) {
        A b = new A(20);
        int sum = 10;
        sum += b.ob;
        System.out.println("Sum = " + sum);
    }
}
class A<T> {
    T ob;
    public A(T ob) {
        this.ob = ob;
    }
    public void print(T ob) {
        System.out.println("Obj = " + ob);
    }
}


Obj = 20
Sum = 30
Obj = 10
Sum = 10
Obj = 10
Sum = 30
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Type Erasure

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App