question 22

Posted Thursday, September 03, 2009 by SacrosanctBlood in

Consider the below classes.

public class AH<E> {

    private E a;

    public void setA (E x) {

        a = x;

    }

    public E getA () {

        return a;

    }

}

public class A {

}

public class C extends A {

}

public class D extends A {

}

For the following code snippets, identify whether the code:

*    fails to compile,
*    generates an error at runtime, or
*    none of the above (compiles and runs without problem.)

a. AH<A> h = new AH<C>();
b. AH<D> h = new AH<A>();
c. AH<?> h = new AH<C>();
   h.setA(new C());
d. AH h = new AH();
   h.setA(new D());

e. AH<? extends A> h = new AH<C>();

  h.setA(new C());



0 comment(s) to... “question 22”

0 comments:

Post a Comment