What difference does an instance make?

Suppose we have a class Worldand we have declared an instance of dreamWorldthis class. How is case 1 different from case 2 except that it is one line shorter? What difference does the instances make in the second case? I mean, after being the dreamWorldsame 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 outerWorldis the class object Worldcreated elsewhere and, say, provided as an argument to the method (I'm not sure if it matters how it is provided).

PS , , ( , , , , , ).

+4
6

1 2, , Case 2 , . ( )

, , , , , , .

, , , , a = .

dreamworld outerworld . , . , , dreamworld . , / dreamworld.

: , , . , , .:) Bean, , :).

0

2 . World, , dreamWorld = outerWorld, .

EDIT:
@Rob, , World - , . dreamWorld , .

+6

1 :

2 :

, , (, , ).

+1

2 dreamWorld = new World();, ,

+1

, World, , .

+1

, , . , /, 1 dreamWorld, 2 , World, 1 .

. , .

java?

0

All Articles