Employee class, which contains fields such as name and designation. And a subclass, which contains a field salary. Write a program for inheriting this relation.
CODING:
CODING:
class Employee
{
String name,designation;
public Employee(String n,String d)
{
name=n;
designation=d;
}
public void EmpDisp()
{
System.out.println("Employee Name:"+name+"\nDesignation:"+designation);
}
}
class EmployeeSalary extends Employee
{
double salary;
public EmployeeSalary(String n,String d,double s)
{
super(n,d);
salary=s;
}
public void EmpDisp()
{
super.EmpDisp();
System.out.print("Salary:"+salary);
}
}
class Emp
{
public static void main(String [] args)
{
EmployeeSalary Emp1=new EmployeeSalary("Mike","Manager",500000);
Emp1.EmpDisp();
}
}
{
String name,designation;
public Employee(String n,String d)
{
name=n;
designation=d;
}
public void EmpDisp()
{
System.out.println("Employee Name:"+name+"\nDesignation:"+designation);
}
}
class EmployeeSalary extends Employee
{
double salary;
public EmployeeSalary(String n,String d,double s)
{
super(n,d);
salary=s;
}
public void EmpDisp()
{
super.EmpDisp();
System.out.print("Salary:"+salary);
}
}
class Emp
{
public static void main(String [] args)
{
EmployeeSalary Emp1=new EmployeeSalary("Mike","Manager",500000);
Emp1.EmpDisp();
}
}
Comments
Post a Comment