Search Java Programs

Monday, February 1, 2010

Inheritance Programs

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Parthiban (Java Programmers)
 */
class box
{
double width;
double height;
double depth;
box(box ob)
{
width=ob.width;
height = ob.height;
depth=ob.depth;
}
box(double w, double h, double d)
{
width = w;
height = h;
depth = d;
}
box()
{
width = -1;
height =-1;
depth = -1;
}
box (double len)
{
width = height = depth = len;
}
double volume()
{
return width * height * depth;
}
}
class boxweight extends box
{
double weight;
boxweight(double w,double h, double d, double m)
{
super(w, h, d);
weight = m;
}
}


public class inherit_1 {
    public static void main(String args[])
    {
       boxweight din = new boxweight(4, 8, 7, 9.1);
       double vol;

       vol = din.volume();
       System.out.println("Volume of " + vol);
        System.out.println("weight of " + din.weight);
    }

}

No comments:

Post a Comment

Website Design by Mayuri Multimedia