What difference does instantiating make?

Viewed 136

Suppose we have a class World and we've declared an instance dreamWorld of that class. How Case 1 is different from Case 2 other than it's one line shorter? What difference does instantiating in the second case actually make? I mean, afterall dreamWorld will be just the same in both cases, right?

Case 1:

void changeWorld(World outerWorld) {
    World dreamWorld;

    dreamWorld = outerWorld;
}

Case 2:

void changeWorld(World outerWorld) {
    World dreamWorld;

    dreamWorld = new World();
    dreamWorld = outerWorld;
}

where outerWorld is an object of World class created elsewhere and, say, provided as a method argument (I'm not sure if it matters how it is being provided).

PS Thank you for all your prompt and helpful replies, guys, and sorry for my delayed gratitude (it took me time to read some literature that I felt would be necessary to fully understand your replies).

6 Answers
Related