import java.util.*;
abstract class dept
{
double bp;
dept(double bpay)
{
bp=bpay;
}
void disp()
{
System.out.println("basicpay="+bp);
}
abstract double bonus();
}
class sales extends dept
{
sales(double bpay)
{
super(bpay);
}
public double bonus()
{
return(0.20*bp);
}
}
class marketing extends dept
{
marketing(double bpay)
{
super(bpay);
}
public double bonus()
{
return(0.30*bp);
}
}
class hr extends dept
{
hr(double bpay)
{
super(bpay);
}
public double bonus()
{
return(0.50*bp);
}
}
class MethodOverload
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter basic pay");
double bp=sc.nextDouble();
sales s=new sales(bp);
s.disp();
System.out.println("bonus for sales dept=" +s.bonus());
marketing m=new marketing(bp);
m.disp();
System.out.println("bonus for marketing dept=" +m.bonus());
hr h=new hr(bp);
h.disp();
System.out.println("bonus for hr dept=" +h.bonus());
}
}
Output
C:\Users\Jaisha\Desktop\Java>javac MethodOverload.java
C:\Users\Jaisha\Desktop\Java>java MethodOverload
enter basic pay
5000
basicpay=5000.0
bonus for sales dept=1000.0
basicpay=5000.0
bonus for marketing dept=1500.0
basicpay=5000.0
bonus for hr dept=2500.0
abstract class dept
{
double bp;
dept(double bpay)
{
bp=bpay;
}
void disp()
{
System.out.println("basicpay="+bp);
}
abstract double bonus();
}
class sales extends dept
{
sales(double bpay)
{
super(bpay);
}
public double bonus()
{
return(0.20*bp);
}
}
class marketing extends dept
{
marketing(double bpay)
{
super(bpay);
}
public double bonus()
{
return(0.30*bp);
}
}
class hr extends dept
{
hr(double bpay)
{
super(bpay);
}
public double bonus()
{
return(0.50*bp);
}
}
class MethodOverload
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter basic pay");
double bp=sc.nextDouble();
sales s=new sales(bp);
s.disp();
System.out.println("bonus for sales dept=" +s.bonus());
marketing m=new marketing(bp);
m.disp();
System.out.println("bonus for marketing dept=" +m.bonus());
hr h=new hr(bp);
h.disp();
System.out.println("bonus for hr dept=" +h.bonus());
}
}
Output
C:\Users\Jaisha\Desktop\Java>javac MethodOverload.java
C:\Users\Jaisha\Desktop\Java>java MethodOverload
enter basic pay
5000
basicpay=5000.0
bonus for sales dept=1000.0
basicpay=5000.0
bonus for marketing dept=1500.0
basicpay=5000.0
bonus for hr dept=2500.0
No comments:
Post a Comment