##Box.java:
class Box<T> {
private T value;
public Box(T value)
{
this.value = value;
}
public T getValue()
{
return value;
}
}
class GenericBox<T> extends Box<T> {
public GenericBox(T value) { super(value); }
public void display() { System.out.println("Value: " + getValue()); }
}
##InheritanceWithGenerics.java
public class InheritanceWithGenerics {
public static void main(String[] args) {
Box<Integer> integerBox = new Box<>(10);
System.out.println("Integer Value: " + integerBox.getValue());
GenericBox<String> stringBox = new GenericBox<>("Hello");
stringBox.display();
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter