Given the constraints that the object instanced of SomeClass is used for multiple requests (e.g. where one request are both invocations of the two methods) and that they must be encapsulated properly, e.g. in a multi user system, you need to have a state object where you can transfer the results of the first method to the second method.
Since the object instance of SomeClass is considered a shared class in this scenario, you need something else.
Two ways:
- Introduce a state object which you can pass from the first method to the second method (e.g. make the first method return the object and pass it as a parameter to the second method)
- Introduce an internal state which is not visible to other callers. This may be risky if you do not know what you are doing and it heavily depends on the context in which the object is being used.
Both options require to change the implementation of the first method.
If you cannot, for any reason, change the implementation of the first method, the answer to your question is: No, you cannot access the soc object from with the second method, as the first object is out of scope, e.g. it may already be garbage collected and gone.
For the latter, you may want to use a ThreadLocal. This comes in handy if you know that a request (for example a HTTP Servlet Request) is unique for a user or a request and so you can share the information/state object in a ThreadLocal between the invocation of the first method and the second method. If you object instance of SomeClass is reused by different Threads, then you need to take care of properly cleaning up!