 <p>Seems there are some basics which are not clear to you.</p> <ol> <li><p>Members are always private and to interact them you should create public setter and getter.</p> <p>public List getUsers(){ return users; }</p> <p>public void getUsers(List users){ this.users=users; }</p></li> <li><p>As a good coding standard, the naming should describe the behavior which provides specific action Hence </p></li> </ol> <p>User addUser(String name)</p> <p>seems very ambiguous considering it's actual implementation as given adds User to the list.</p> <ol start="3"> <li><p>If DB class is a dependency then it should be instantiated Let's assume you are calling this code from main</p> <p>User user= new User(); DB dbInstance=new DB(); dbInstance.setUsers(new ArrayList()); dbInstance.getUsers().add(user);</p></li> </ol> <p>To provide a more specific answer awaiting further requested details</p>