Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Why is answer A correct and not answer B?? I always thought a class has to implement an interface!! Is it different with generics?

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Why is answer A correct and not answer B?? I always thought a class has to implement an interface!! Is it different with generics?

    QUESTION: 163
    A programmer must create a generic class MinMax and the type parameter of MinMax
    must implement Comparable. Which implementation of MinMax will compile?
    A. class MinMax<E extends Comparable<E>> {
    E min = null;
    E max = null;
    public MinMax() {}
    public void put(E value) { /* store min or max */ }
    B. class MinMax<E implements Comparable<E>> {
    E min = null;
    E max = null;
    public MinMax() {}
    public void put(E value) { /* store min or max */ }
    C. class MinMax<E extends Comparable<E>> {
    <E> E min = null;
    <E> E max = null;
    public MinMax() {}
    public <E> void put(E value) { /* store min or max */ }
    D. class MinMax<E implements Comparable<E>> {
    <E> E min = null;
    <E> E max = null;
    public MinMax() {}
    public <E> void put(E value) { /* store min or max */ }

    Correct Answer: A


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Why is answer A correct and not answer B?? I always thought a class has to implement an interface!! Is it different with generics?


  3. The Following User Says Thank You to curmudgeon For This Useful Post:

    TheCoder (March 9th, 2013)

  4. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Why is answer A correct and not answer B?? I always thought a class has to implement an interface!! Is it different with generics?

    The link was fantastic advice. I found my answer. Many thanks

  5. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Why is answer A correct and not answer B?? I always thought a class has to implement an interface!! Is it different with generics?

    You're welcome.

Similar Threads

  1. Can somebody help me to answer this? Thanks!
    By dshainad in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 13th, 2012, 09:47 PM
  2. What's ur answer?
    By Tanmaysinha in forum The Cafe
    Replies: 6
    Last Post: October 12th, 2011, 06:26 AM
  3. [SOLVED] Answer always false.
    By tyb97 in forum Loops & Control Statements
    Replies: 5
    Last Post: October 7th, 2011, 10:56 AM
  4. need answer for these
    By satishbs in forum Java Theory & Questions
    Replies: 2
    Last Post: April 15th, 2011, 01:46 AM
  5. Arrays.equals not returning correct answer.
    By Anyone in forum Collections and Generics
    Replies: 2
    Last Post: February 11th, 2010, 10:12 AM

Tags for this Thread