A non-generic class can be the base class of a generic derived class : Generic Class Hierarchy « Generics « C# / C Sharp






A non-generic class can be the base class of a generic derived class

A non-generic class can be the base class of a generic derived class

using System;

class MyBaseClass {
  int num;

  public MyBaseClass(int i) {
    num = i;
  }

  public int getnum() {
    return num;
  }
}

class MyGenericClass<T> : MyBaseClass {
  T ob;

  public MyGenericClass(T o, int i) : base (i) {
    ob = o;
  }

  public T getob() {
    return ob;
  }
}

class HierDemo3 {
  public static void Main() {

    MyGenericClass<String> w = new MyGenericClass<String>("Hello", 7);

    Console.WriteLine(w.getob());
    Console.WriteLine(w.getnum());
  }
}
           
       








Related examples in the same category

1.A simple generic class hierarchyA simple generic class hierarchy
2.A derived class with its own type parametersA derived class with its own type parameters
3.Overriding a virtual method in a generic classOverriding a virtual method in a generic class
4.The overriding method cannot change the inherited constraints.