title: Generalized method to get sum of any data type in java
body: <p>I want a general method which can give me output for any data type passed to its arguments.</p>
  
  <p>For example:</p>
  
  <p>We have to write many same implementations for different data types.</p>
  
  <pre><code>class Test {
  
      public static void main(String args[]) {
          int x=sum(1,2);
          double y=sum(1.11,2.22);
          String z=sum("1","2");
      }
  
      static public int sum(int a, int b) {
          return a + b;
      }
  
      static public double sum(double a, double b) {
          return a + b;
      }
  
      static public String sum(String a, String b) {
          return a + b;
      }
  }
  </code></pre>
  
  <p>Need only one method which can accept any data type and return the output.</p>