Sunday, 16 June 2013

Inheritance program in java

class Employee
{
    private int eno;
    private String name;
    private float bs;
    private int hra,da,ta;
    public Employee()
    {
        eno=0;
        name="Empty";
        bs=0;
    }
    public Employee(int eno,String name,float bs,int hra,int da,int ta)
    {
        this.eno=eno;
        this.name=name;
        this.bs=bs;
    }
    public String toString()
    {
        return "\n 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 hra,int da,int ta, int hours, int rate)
    {
        super(eno,name,bs,hra,da,ta);
        this.hours=hours;
        this.rate=rate;
    }
    public String toString()
    {
        return super.toString()+"\n Hours -"+hours+"\n Rate -"+rate;
    }
}   
class Manager extends Employee
{
    private int inc;
    public Manager()
    {
        inc=0;
    }
    public Manager(int eno,String name,float bs,int hra,int da,int ta,int inc)
    {
        super(eno,name,bs,hra,da,ta);
        this.inc=inc;
    }
    public String toString()
    {
        return super.toString()+"\n Incentave-"+inc;
    }
}
class inher
{
    public static void main(String args[])
    {
        WageEmp we=new WageEmp(1,"Amit",2000.0f,9,8,8,10,5);
        Manager mgr=new Manager(111,"Ajay",1000.0f,10,11,13,5550);
        System.out.println("WageEmp \n"+we);
        System.out.println("=======================================");
        System.out.println("Manager \n"+mgr);
    }
}

No comments: