Menu
Topics Index
...
`

Generics Are Fun And Useful


If you need explanation Read this topic

If you need Answer Take test on this topic

Generics Are Fun And Useful
At what line will there be a compilation error?
public class Generics {
    public static void main(String[] args) {
        B b = new B(); /* LINE A */
        C c = b.process(new C()); /* LINE B */
        B<C> b2 = new B<C>(); /* LINE C */
        C c2 = b2.process(new C()); /* LINE D */
    }
}
interface A {
    int count();
    void show();
}
class B<T extends A> {
    T process(T t) {
        t.count();
        t.show();
        return t;
    }
}
class C implements A {
    public int count() { return 25; }
    public void show() { System.out.print("Class C"); }
}

A. LINE A
B. LINE B
C. LINE C
D. LINE D
E. Compilation Error at some other line
F. No Compilation Errors
Topic: Java Generics

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.

B. is ans.at line B error occurs due to incompatible type.

Posted by Shabaaz Shaikz    2014-04-04 12:42:37


Ans is B : coz of  Type mismatch,cannot convert from A to C !! inorder to remove the error,either ass cast to C or else change the obj c type to A

Posted by Shaik Nyamath    2014-04-04 12:54:37


Congratulations Shabaaz Shaikz. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-04-07 13:32:33


ThankQ :-)

Posted by Shabaaz Shaikz    2014-04-07 13:33:46


© meritcampus 2019

All Rights Reserved.

Open In App