title: Sending different objects to Server in Java
body: <p>I have a couple of classes.
  Student, Teacher and Book.</p>
  
  <p>I want to send instances of those 3 objects from server to the connecting client.
  I know how to send/receive instances of single type, i.e. Student from server to client using the following code</p>
  
  <p>Client Side</p>
  
  <pre><code>            Socket socket = new Socket(ip, port);
          try {
              ObjectInputStream objectInput = new ObjectInputStream(socket.getInputStream());
              try {
                  Object object =(Student) objectInput.readObject();
                  Student std = (Student) object;
                  //do something with std
              } catch (ClassNotFoundException e) {
                  e.printStackTrace();
              }          
  </code></pre>
  
  <p>Server Side</p>
  
  <pre><code>        Student a = new Student();
          ServerSocket myServerSocket = new ServerSocket(port);
          Socket skt = myServerSocket.accept();   
          try 
          {
              ObjectOutputStream objectOutput = new ObjectOutputStream(skt.getOutputStream());
              objectOutput.writeObject(a);                
          } 
          catch (IOException e) 
          {
              e.printStackTrace();
          } 
  </code></pre>
  
  <p>How to extend this code to be able to send different types of objects from server and receive them correctly on the client side</p>
  
  <p>Do I need to wrap them all in another object and give each one a type?
  Thanks!</p>