A Generic Subclass: a nongeneric class can be the superclass of a generic subclass : Generic Class Hierarchies « Generics « Java Tutorial






A nongeneric class can be the superclass of a generic subclass.

class NonGen {
  int num;

  NonGen(int i) {
    num = i;
  }

  int getNumber() {
    return num;
  }
}

class Gen<T> extends NonGen { 
  T ob; 
   
  Gen(T o, int i) { 
    super(i);
    ob = o; 
  } 
 
  T getObject() { 
    return ob; 
  } 
} 
 
public class MainClass { 
  public static void main(String args[]) { 
    Gen<String> w = new Gen<String>("Hello", 47);
   
    System.out.print(w.getObject() + " ");
    System.out.println(w.getNumber());
  } 
}
Hello 47








12.7.Generic Class Hierarchies
12.7.1.Generic Class Hierarchies: uses a generic superclass
12.7.2.A subclass can add its own type parameters, if needed.
12.7.3.A Generic Subclass: a nongeneric class can be the superclass of a generic subclass
12.7.4.Run-Time Type Comparisons Within a Generic Hierarchy
12.7.5.Casting within a generic class hierarchy
12.7.6.Overriding Methods in a Generic Class