Generic constructors and methods in non-generic class

It is possible for constructors / methods to be generic, even if their class is not.

// Generic programming
// Generic constructors in non generic class
class Gen
{
     double x;
     <T1 extends Number>Gen(T1 v)
     {
          x = v.doubleValue();
     }
     public void fnDisplay()
     {
          System.out.println(“x = “+x);
     }
}
class GenPgm5
{
     public static void main(String as[])
     {
          Gen g1 = new Gen(5);
          g1.fnDisplay();
          Gen g2 = new Gen(4.5);
          g2.fnDisplay();
     }
}

// Generic programming
// Generic methods in non generic class
class Gen
{
     public <T1 extends Number> void fnSum(T1 x, T1 y)
     {
          double sum = x.doubleValue() + y.doubleValue();
          System.out.println(“Sum = “+sum);
     }
}
class GenPgm6
{
     public static void main(String as[])
     {
          Gen g1 = new Gen();
          g1.fnSum(5,6);
          Gen g2 = new Gen();
          g2.fnSum(4.5, 5.2);
     }
}