Results 1 to 5 of 5

Thread: need help with java exercise

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    27

    need help with java exercise

    hello everyone, i was going through exercise in book and here is the part i need some help.

    Consider this code that creates some location objects with coordinates x=10 and y=20:

    Location a, b, c;
    a=new Location (10,20);
    b=new Location (10,20);
    c=b;

    after this code executes, what are the values of these boolean expressions?

    A= =b
    a.equals(b)
    a= =c
    a.equals(c)
    b= =c
    b.equals(c)

  2. #2
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: need help with java exercise

    i would say.

    false
    false
    false
    false
    true
    true

  3. #3
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: need help with java exercise

    The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).
    and well even if a and b has the same data they are essentially two different objects.
    hope my understanding is correct.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: need help with java exercise

    false, true, false, true, true, true, if Location implements a sane equals().

    It's really not hard. == checks if two references point to the same object. equals compares the objects themselves in some way that depends on the object.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    27

    Re: need help with java exercise

    thanks for your responce

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width