Example of Generic class with two type parameters.


class TwoGen<T,V>

{T ob1;

V ob2;

TwoGen(T o1, V o2)

{ ob1=o1;

ob2=o2;

}

void showTypes()

{System.out.println("Type of T is "+ ob1.getClass().getName());

System.out.println("Type of V is "+ ob2.getClass().getName());

}

T getob1()

{ return ob1;

}

V getob2()

{return ob2;

}

}

class GenDemo2

{public static void main(String a[])

{TwoGen<Integer,String> tgobj= new twoGen<Integer,String>(88,"Generics");

tgobj.showTypes();

int t=tgobj.getob1();

System.out.println("value of t: "+t);

String str =tgobj.getob2();

System.out.println("value of str: "+ str);

}
}
Advertisements

One thought on “Example of Generic class with two type parameters.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s