Overriding methods in generic class:

A method in a generic class can be overridden just like other class.
Example:
class Gen1
{
void getobj(T i){
System.out.println("this is Gen1\t"+i);}
};
class Gen2 extends Gen1
{
void getobj(T i){
System.out.println("this is Gen2\t"+i);
}
};
class demo
{
public static void main(String[] args){
Gen1 i=new Gen1();
i.getobj(new Integer(10));

Gen1 i2=new Gen2();
i2.getobj(new Integer(20));

}};

No comments:

Post a Comment