title: Create Fields and methods dynamically
body: <p>I want to add new fields(variables) and encapsulating methods for a given class. For example: A class name Student has no any fields like below:</p>
  
  <pre><code>public class Student implements Serializable{
  
  }
  </code></pre>
  
  <p>then in my application an instance is created;</p>
  
  <pre><code>Student s=new Student();
  </code></pre>
  
  <p>I want to add new methods which do not exist for student class at the run time.for example: I want to add a field called <code>studentName</code>, and <code>getStudentName()</code> and <code>setStudentName()</code> methods.</p>
  
  <p>Then at the run time the student object will be like this;</p>
  
  <pre><code>public class Student implements Serializable{
  
      private String studentName;
  
      public void setStudentName(..){}
      public String getStudentName(){return ...;}
  }
  </code></pre>
  
  <p>In my application objects are written to a text file and all objects of same type do not have all variables. Therefore, I want to add only the required fields to save memory.</p>
  
  <p>Any way is there a way to do this? Any sample code or link?</p>
  
  <p><strong>EDIT:  or else can we create a class either and create instances which does not exists ?</strong></p>
  
  <p>EDIT 2: Thanks all of you answered and got many info and ideas. And changed the way to a better path from your suggestions as well</p>