Menu
Question Index
...

What will be the output of the following program?

public class Generic<T> {
    private T t;
    public void set(T t) { this.t = t;  }
    public T get() {
        return t;
    }
    public <U extends Number> void inspect(U u) {
        System.out.println("T: " + t.getClass().getName());
        System.out.println("U: " + u.getClass().getName());
    }
    public static void main(String[] args) {
        Generic<Integer> integerBox = new Generic<Integer>();
        integerBox.set(10);
        integerBox.inspect(new Number("12"));
    }
}


T: java.lang.Integer
U: java.lang.Integer
T: java.lang.Integer
U: java.lang.Number
Compilation Error
throws NumberFormatException
Compilation Error or 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