可以被继承,代码是网上找的希望对你有所帮助:
class Father<T> {
T t;
Father(T t) {
this.t = t;
}
public void fatherPrint() {
System.out.println("father's " + t);
}
}
class Son<T> extends Father {
Son(T t) {
super(t);
}
public void sonPrint() {
System.out.println("son's " + t);
}
}
public class Test {
public static void main(String[] args) {
Father<Integer> f = new Son<Integer>(new Integer(4));
f.fatherPrint();
Son<Integer> s = (Son<Integer>) f;
s.sonPrint();
}
}
|