Menu
Topics Index
...
`

Bounded Types2870


If you need explanation Read this topic

If you need Answer Take test on this topic

Bounded Types2870
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;
    }
}

A. Value 1 :16.0
Value 2 :30.0
B. Value 2 :30.0
Value 1 :16.0
C. Compilation Error
D. Runtime Error
Topic: Java Bounded Type - Bounded Type In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans a.
addsum methd cald n 5+11
16.0 printd
again addsum float values cald
30.0 prinrd

Posted by Maheshwari Natarajan    2014-08-22 08:53:55


ans c.
compilation err.
1st methd cal getsum() return doubl

Posted by NagaRaj Nataraj    2014-08-22 08:59:05


Answer is C as obj1.addSum(new Float(11.5)) and the next line will throws a error as obj1 belongs to java.lang.Integer and java.lang.Float can't be applied to it which is a Type Mismatch

Posted by Sai Avinash    2014-08-22 09:04:07


No winner for this dose. Correct option is 'C' :(. Sai Avinash was already won in this week.

Posted by Merit Campus    2014-08-25 07:27:22


© meritcampus 2019

All Rights Reserved.

Open In App