Question: Is there a reason to prefer using shared instance variable in class vs. local variable and have methods return the instance to it? Or is either one a bad practice?

```
import package.AClass;

public class foo {
    private AClass aVar = new AClass();

    // ... Constructor

    public AClass returnAClassSetted() {
     doStuff(aVar);

     return avar;
    }

    private void doStuff(AClass a) {
     aVar = a.setSomething("");
    }
}

```

vs. 

```
import package.AClass;

public class foo {

    // ... Constructor

    public AClass returnAClassSetted() {
     AClass aVar = new AClass();
     aVar = doStuff();

     return aVar;
    }

    private AClass doStuff() {
     AClass aVar1 = new AClass();
     aVar1.setSomething("");

     return aVar1;
    }
}

```

First one makes more sense to me in so many ways but I often see code that does the second. Thanks!

Answer: 
Your class name should have been `Foo`.

The two versions you have are not the same, and it should depend on your use case. 

The first version returns the same `AClass` object when different callers call `returnAClassSetted()` method using the same `Foo` object. If one of them changes the state of the returned `AClass` object, all of them will get see the change. Your `Foo` class is effectively a [Singleton](https://en.wikipedia.org/wiki/Singleton_pattern). 

The second version returns a new `AClass` object every time a caller calls `returnAClassSetted()` method using either the same or different `Foo` object. Your `Foo` class is effectively a [Builder](https://en.wikipedia.org/wiki/Builder_pattern).

Also, if you want the second version, remove the `AClass aVar = new AClass();` and just use `AClass aVar = doStuff();`. Because you are throwing away the first `AClass` object created by `new AClass();`
Instance properties represent the state of a specific instance of that Class. It might make more sense to think about a concrete example. If the class is Engine, one of the properties that might represent the state of the Engine might be

```
private boolean running;

```

... so given an instance of Engine, you could call engine.isRunning() to check the state.

If a given property is not part of the state (or composition) of your Class, then it might be best suited to be a local variable within a method, as implementation detail.