Question

When creating an object(or anything) in java, what is the difference between doing, for example,

Dog d = new Dog();

instead of doing

Dog d;

and then later, finishing it off(sometimes inside and at the beginning of a method) with

d = new Dog();

Wouldn't the first one be more simple and easier? Why do people do it the second way?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top