inheritance using generics
Wed May 29 2024 10:18:09 GMT+0000 (Coordinated Universal Time)
Saved by
@signup
class Superclass<T> {
private T element;
public Superclass(T element) {
this.element = element;
}
public T getEle() {
return this.element;
}
}
class Subclass<T, V> extends Superclass<T> {
private V value;
public Subclass(T element, V value) {
super(element);
this.value = value;
}
public V getValue() {
return this.value;
}
}
public class Hierarchy {
public static void main(String[] args) {
System.out.println(" ABC");
Subclass<String, Integer> h1 = new Subclass<>("abc", 123);
System.out.println(h1.getEle());
System.out.println(h1.getValue());
}
}
content_copyCOPY
Comments