Menu
Question Index
...

What will be the output of the following program?

public class BoundTypeDemo2 {
    public static void main(String args[])
    {
        BoundedType2<Integer> obj1 = new BoundedType2<Integer>();
        obj1.addSum(5);
        obj1.addSum(11);
        System.out.println("Value 1 :" + obj1.getSum());
        BoundedType2<Float> obj2 = new BoundedType2<Float>();
        obj1.addSum(new Float(11.5));
        obj1.addSum(new Float(18.5));
        System.out.println("Value 2 :" + obj2.getSum());
    }
}

class BoundedType2<T extends Number> {
    double sum = 0.0;
    void  addSum(T item)
    {
        sum+=item.doubleValue();
    }
    double getSum()
    {
        return sum;
    }
}


Value 1 :16.0
Value 2 :30.0
Value 2 :30.0
Value 1 :16.0
Compilation Error
Runtime Error

Doubts

Problems

Topic: Java Bounded Type - Bounded Type 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