A simple generic class hierarchy : Generic Class Hierarchy « Generics « C# / C Sharp






A simple generic class hierarchy

A simple generic class hierarchy

using System;

class GenericClass<T> {
  T myObject;

  public GenericClass(T o) {
    myObject = o;
  }

  public T getmyObject() {
    return myObject;
  }
}

class GenericClass2<T> : GenericClass<T> {
  public GenericClass2(T o) : base(o) {
  }
}

class Test {
  public static void Main() {
    GenericClass2<string> g2 = new GenericClass2<string>("www.java2s.com");

    Console.WriteLine(g2.getmyObject());
  }
}
           
       








Related examples in the same category

1.A derived class with its own type parametersA derived class with its own type parameters
2.A non-generic class can be the base class of a generic derived classA non-generic class can be the base class of a generic derived class
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.