Generic Class In Java



Generic Class In Java:-

If we want to create a class that can accept common type data as a class argument and method argument then we can create a Generic class.

It is used to provide type safety features to classes and methods both and reduce program code to declare multiple type method.

it is similar to template in c#, we can provide flexbility to class and methods to use Generic.

Example of  Generic Cass In java:-

class Ope<T>

{  T obj;

  Ope(T obj)




    T getObject()

  {       return this.obj;



class OpeMain


   public static void main(String args[])


       Ope<Integer> o = new Ope<Integer>(10);


       Ope<Float> o1 = new Ope<Float>(10.23F);





Post a Comment


POST Answer of Questions and ASK to Doubt

Post a Comment (0)