Generic Programming Example -2
class GenericDemo2<T, E>
{
T obj;
E obj2;
// Pass the constructor a reference to an Object of type T
public GenericDemo2(T obj, E obj2) {
this.obj = obj;
this.obj2= obj2;
}
// return Object
public T getObj() {
return obj;
}
public E getObj2() {
return obj2;
}
void showType()
{
System.out.println("Type of T is :" + obj.getClass().getName());
System.out.println("Type of E is :" + obj2.getClass().getName());
}
}
public class GenericTypeTesting2 {
public static void main(String[] args) {
GenericDemo2<Integer, String> intojb = new GenericDemo2<Integer,String >(210, "ISTAR");
System.out.println(intojb.getObj());
System.out.println(intojb.getObj2());
intojb.showType();
GenericDemo2<String, Double> strobj = new GenericDemo2<String, Double>("ISTAR", 20.80);
System.out.println(strobj.getObj());
System.out.println(strobj.getObj2());
strobj.showType();
}
}
Comments
Post a Comment