Menu
Question Index
...

What will be the output of the following program?

public class GenericsWildCardsDemo {
    public static void main(String args[])
    {
        Variables<Double> obj = new Variables<Double>(45.0, 55.0);
        print(obj);
    }
    public static void print(Variables<? extends Number> var)
    {
        System.out.println(var.getAddition());
    }
}
class Variables<T extends Number>
{
    T x;
    T y;
    Double sum = 0.0;
    public Variables(T x, T y) {
        this.x = x;
        this.y = y;
    }
    public Double getAddition()
    {
        sum+= x.doubleValue() + y.doubleValue();
        return sum;
    }
}


100.0
0.0
Compilation Error
Runtime Error

Doubts

Problems

Topic: Generics Wildcards In Java With Examples

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App