You are here: Home / Topics / Program to explain that a subclass can add its own type parameters in Java

Program to explain that a subclass can add its own type parameters in Java

Filed under: Java on 2024-04-13 09:09:13

//  Program to explain that a subclass can add its own type parameters.

class  Gen<T> 
{
T ob;

Gen(T o) 
{
 ob = o;
}

T getob() 
{
 return ob;
}
}

class  Gen2<T, V> extends Gen<T> 
{
V ob2;

Gen2(T o, V o2) 
{
 super(o);
 ob2 = o2;
}

V getob2() 
{
 return ob2;
}
}

public class  GenericTest15e 
{
public static void main(String args[ ]) 
{
 Gen2<String, Integer> x = new Gen2<String, Integer>("Value is: ", 100);
 System.out.print(x.getob());
 System.out.println(x.getob2());
}
}


Output:

Value is: 100

About Author:
J
Java Developer     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.