In: Computer Science
class Employee
{
String name;
protected double salary;
Employee()
{
}
public void setEmployee( String n, double s)
{
name=n;
salary=s;
}
public String getName( )
{
return name;
}
public double getSalary( )
{
return salary;
}
public void print( )
{
System.out.println("Name: "+name+" Salary: "+salary);
}
}
class Manager extends Employee
{
int numEmps;
Manager()
{
}
public void setManager( String n, double s, int e)
{
name=n;
salary=s;
numEmps=e;
}
public int getNumEmps()
{
return numEmps;
}
public double getSalary()
{
return salary;
}
public void print()
{
System.out.println("Name: "+name+" Salary: "+salary+" NumEmps: "+numEmps);
}
}
class Programmer extends Employee
{
String language;
Programmer()
{
}
public void setProgrammer(String n, double s, String l)
{
name=n;
salary=s;
language=l;
}
public String getLanguage()
{
return language;
}
public double getSalary( )
{
return salary;
}
public void print()
{
System.out.println("Name: "+name+" Salary: "+salary+" Language: "+language);
}
}
class main
{
public static void main (String[] args)
{
Programmer p= new Programmer();
p.setProgrammer("Ahmed Hasan", 8550,"Java");
Manager m=new Manager();
Employee e=m;
e.print();
e=p;
e.print();
}
}
I hope it helps.