object declarations

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bucketbot
    New Member
    • May 2007
    • 9

    #1

    object declarations

    just a quick questions that has been bugging me for a few days:

    lets say i have some classes X and Y, and in some other part of the program, I make this declaration:

    X xObject = new yObject();

    What does that do?

    thanks
  • tmerkaj
    New Member
    • Jun 2007
    • 6

    #2
    Originally posted by bucketbot
    just a quick questions that has been bugging me for a few days:

    lets say i have some classes X and Y, and in some other part of the program, I make this declaration:

    X xObject = new yObject();

    What does that do?

    thanks
    that does not work
    but you can cast to do that
    ex: X xObject =(X)( new yObject());

    Comment

    • tmerkaj
      New Member
      • Jun 2007
      • 6

      #3
      Originally posted by tmerkaj
      that does not work
      but you can cast to do that
      ex: X xObject =(X)( new yObject());
      of course if casting is allowed which will depend on the types of x and y

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by bucketbot
        just a quick questions that has been bugging me for a few days:

        lets say i have some classes X and Y, and in some other part of the program, I make this declaration:

        X xObject = new yObject();

        What does that do?

        thanks

        You can do[CODE=java] List c = new ArrayList();[/CODE] .

        Think about it and come up with the instances where it is allowed to do so. Don't forget to test for interfaces as well ...

        Comment

        • bucketbot
          New Member
          • May 2007
          • 9

          #5
          ok, lets say its type casted. i dont understand what the xObject becomes if the yObject is stored into it.

          thanks

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by bucketbot
            ok, lets say its type casted. i dont understand what the xObject becomes if the yObject is stored into it.

            thanks
            How about you think about this in terms reference types and what they are pointing to?


            e.g
            [CODE=java] X x = new Y();[/CODE]
            The reference x of type X is pointing to an object of type Y.

            Comment

            Working...