Menu
Topics Index
...
`

Genericinterfaces


If you need explanation Read this topic

If you need Answer Take test on this topic

Genericinterfaces
What will be the output of the following program?
public class BoxAndBottle {
    public static void main(String[] args) {
        Box a = new Box();
        a.add(10);
        System.out.println(a.get());
        Bottle b = new Bottle();
        b.add("Hello");
        System.out.println(b.get());
    }
}
interface a<T> {
    public void add(T t);
}
class Box implements a<Integer> {
    int t;
    public void add(Integer t) {
        this.t = t;
    }
    public int get() {
        return t;
    }
}
class Bottle implements a<String> {
    public void add(String t) {
    }
    public String get() {
        return "Hai";
    }
}

A. 10
Hai
B. 10
Hello
C. Some other output
D. Compilation Error
E. Runtime Error
Topic: Generic Interface 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.

d.integer values r pased as argument wher objct is required

Posted by Shamee Shamee    2014-08-28 08:33:43


a

add() is tkng 10 as argument.in box clas objects r invoked.

so prnt stmt wil prnt 1o n hell.as get fn is retrng hell

Posted by Shamee Shamee    2014-08-28 08:36:02


Ans: A . in the first Box class object created and then add method is caleld and then get method output....so it will return 10..and then next bottle class obj is crated and then add method called and then fllowed by get method we will get 'hai" output on screen..

Posted by Sapparapu Pradeep Kumar    2014-08-28 08:49:54


A

Posted by Mark Kovach    2014-08-28 13:43:42


Congratulations Sapparapu Pradeep Kumar. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-09-01 06:01:32


© meritcampus 2019

All Rights Reserved.

Open In App