// Generic programming
// Inheritance and
constructors
class GenA<T1 extends Number>
{
public T1 l, b;
double area;
GenA(T1 x, T1 y)
{
l = x;
b = y;
}
public void fnArea()
{
area =
l.doubleValue()*b.doubleValue();
System.out.println("Area
= "+area);
}
}
class GenV<T1 extends Number> extends GenA<T1>
{
T1 h;
double vol;
GenV(T1 x, T1 y, T1 z)
{
super(x,y);
h = z;
}
public <T1 extends
Number> void fnVol()
{
vol =
l.doubleValue()*b.doubleValue()*h.doubleValue();
System.out.println("Volume
= "+vol);
}
}
public class Generics_Demo
{
public static void
main(String as[])
{
GenV<Double> g1
= new GenV<Double>(4.2,5.6,6.1);
g1.fnArea();
g1.fnVol();
}
}
No comments:
Post a Comment
Don't be a silent reader...
Leave your comments...
Anu