Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

 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)

  {

     this.obj=obj;

  }     

  

  T getObject()

  {

       return this.obj;

  } 

}


class OpeMain

{

   public static void main(String args[])

   {

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

       System.out.println(o.getObject());

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

       System.out.println(o1.getObject());


   }


}




Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post