Results 1 to 3 of 3

Thread: Doubt with Generics(Urgent)

  1. #1
    Expert Member
    Join Date
    Oct 2005

    Doubt with Generics(Urgent)

    I have confusion with below code...

    which of them are valid inserts?
    class Parent<E>
    public E get() { return null;}
    public void set(E e) { }
    class Child extends Parent<Number>
    //insert here

    options given to insert are

    a public Object get() { ... }
    b public Long get() { ... }
    c public void set(Object arg) { ... }
    d public void set(Long arg) { ... }
    e public Number get() { ... }

    and ans is b,d,e.Iam fine with it.

    But i have confusion with option c.Why "option c" is wrong?In option c,
    we hava "Object arg" as argument, so isn't it a valid overloading example?

    see here their is a statement in above code "class child extends Parent<Number> ".
    set(E e) of Parent class should be "set(Number e), "

    and in child class if we have option c, which is set(Object e), then what is wrong in it?Wont it be a vaild overloading example.

    Last edited by vmshenoy; 12-23-2007 at 09:16 AM.

  2. #2

    Re: Doubt with Generics(Urgent)

    I am a new member to the forum.
    I think this is possible in java 1.5 but for the previous versions it is not possible.

  3. #3
    Contributing Member
    Join Date
    Nov 2007

    Re: Doubt with Generics(Urgent)

    yes, previous version is not suitable for overloading classes in the collection frame work. overloading can be done throw constructor call only. interfaces provides constructor call

  4.  Sponsored Ads


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.