Source Code : Java hierarchy generic class

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Java hierarchy generic class

Java hierarchy generic class
   
/*
Java 2, v5.0 (Tiger) New Features
by Herbert Schildt
ISBN: 0072258543
Publisher: McGraw-Hill/Osborne, 2004
*/
// Here, T is bound by Object by default. 
class Gen<T> {  
  T ob; // here, T will be replaced by Object 
    
  Gen(T o) {  
    ob = o;  
  }  
  
  // Return ob.  
  T getob() {  
    return ob;  
  }  
}  
 
// Here, T is bound by String. 
class GenStr<T extends String> { 
  T str; // here, T will be replaced by String 
 
  GenStr(T o) {  
    str = o;  
  }  
 
  T getstr() { return str; } 
}

public class GenTypeDemo {  
  public static void main(String args[]) {  
    Gen<Integer> iOb = new Gen<Integer>(99);  
    Gen<Float> fOb = new Gen<Float>(102.2F); 
 
    System.out.println(iOb.getClass().getName()); 
    System.out.println(fOb.getClass().getName()); 
  } 
}

           
         
    
    
  

Thank with us