Create a class with a generic type
T. A subclass of the class that defines a second type parameter, calledV. Call the methods from both classes using the object. Create 2 objects with different objects
This is the question.
This is not homework if anyone might think. I am doing some java papers for practice. I don’t understand how to “create 2 objects with different objects”. Can anyone help?
class Gen<T>
{
T obj;
Gen(T ob)
{
obj = ob;
}
T getobj()
{
return obj;
}
}
class Gen2<T, V> extends Gen<T>
{
V obj1;
Gen2(T ob,V ob1)
{
super(ob);
obj1 = ob1;
}
V getobj1()
{
return obj1;
}
}
public class Ch2Lu4Ex3
{
public static void main(String args[])
{
Gen2<String,String> g = new Gen2<String,String>("robin","raj");
System.out.println(g.getobj1());
System.out.println(g.getobj());
}
}
Well, you could do things like:
Or you could combine them since they are on the same hierarchy.