Answer:
The answer to the following question is Generic classes.
Explanation:
The declaration of the generic classes is the same as the declaration of non-generic classes but except the class name has followed by the type of parameter section.
The parameter section of the generic class can have only one or more than one type parameter which is separated by the commas.
Following example can explain that how can define generic class.
public class demo<D> {
private D d;
public void fun(D d) {
this.d = d;
}
public D get() {
return d;
}
public static void main(String[] args) {
demo<Integer> integerdemo = new demo<Integer>();
demo<String> stringdemo = new demo<String>();
integerdemo.fun(new Integer(10));
stringdemo.fun(new String("Hello World"));
System.out.printf("The Integer Value is :%d\n\n", integerdemo.get());
System.out.printf("The String Value is :%s\n", stringdemo.get());
}
}