Menu
Question Index
...

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 String get() {
        return "Hai";
    }
}


10
Hai
10
Hello
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Generic Interface 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