title: Fragment accessing other java class
body: <p>I have been searching the internet, but could not get the correct answer that I need. I am new to Android, so please provide a detailed answer.</p>
  
  <p>I have a Fragment which gets some data from the user, ex: name, occupation etc. Every single time I get the data, I would like to store it using GSON to sharedPreferences.  Based on the searches, I will need to construct a regular Java user class and pass the object (<a href="https://stackoverflow.com/questions/29406945/android-save-object-to-sharedpreferences-and-get-it-anywhere-in-the-app">Android - save Object to SharedPreferences and get it anywhere in the app</a>). </p>
  
  <ol>
  <li><p>So the question that I have is, can Fragments access other regular java class functions? </p>
  
  <pre><code>class UserFragment extends Fragment {
  
  // get the data from editText
  
  User newUser = new User("Tom");
  newUser.setOccupation("Programmer");
  
  //etc
  
  }
  </code></pre></li>
  <li><p>Can a Fragment instantiate a class and set variables? </p></li>
  <li>If yes to 1 and 2, where do we add the user class java file, same file as the fragment implementation of another folder and then include it?</li>
  </ol>
  
  <p>I just provided a user as an example, but generically I would like to know the answer to 1 and 2.</p>
  
  <p>Thanks </p>