INHERITANCE WITH GENERICS
Wed May 29 2024 16:36:18 GMT+0000 (Coordinated Universal Time)
Saved by
@signup
##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();
}
}
content_copyCOPY
Comments