Saturday, 15 June 2013

java inheritance program

class Employee
{
    private int eno;
    private String name;
    private float bs;
    public Employee()
    {
        eno=0;
        name="Empty";
        bs=0;
    }
    public Employee(int eno,String name, float bs)
    {
        this.eno=eno;
        this.name=name;
        this.bs=bs;
    }
    public String toString()
    {
        return "Eno - "+eno+"\n Name - "+name+"\n Salary - "+bs;
    }
}
class WageEmp extends Employee
{
    private int hours,rate;
    public WageEmp()
    {
        hours=0;
        rate=0;
    }
    public WageEmp(int eno,String name,float bs, int hours, int rate)
    {
        super(eno,name,bs);
        this.hours=hours;
        this.rate=rate;
    }
    public String toString()
    {
        return super.toString()+"\n Housr -"+hours+"\n Rate - "+rate;
    }
}
class EmpDemo
{
    public static void main(String []args)
    {
        WageEmp we=new WageEmp(123,"Amit",3000.0f,10,5);
        System.out.println("Wage Emp is - "+we);
    }
}       

No comments: