fork download
  1. //Task-4:Abstraction
  2.  
  3. abstract class Payment {
  4.  
  5. abstract void makePayment(double amount);
  6. }
  7. class CreditCardPayment extends Payment {
  8.  
  9. @Override
  10. void makePayment(double amount) {
  11. System.out.println("Payment of " + amount + " made using Credit Card.");
  12. }
  13. }
  14.  
  15. class UPIPayment extends Payment {
  16.  
  17. @Override
  18. void makePayment(double amount) {
  19. System.out.println("Payment of " + amount + " made using UPI.");
  20. }
  21. }
  22.  
  23. public class Main
  24. {
  25. public static void main(String[] args) {
  26. Payment p;
  27.  
  28. p = new CreditCardPayment();
  29. p.makePayment(5000);
  30.  
  31. p = new UPIPayment();
  32. p.makePayment(2000);
  33. }
  34. }
Success #stdin #stdout 0.15s 57640KB
stdin
Standard input is empty
stdout
Payment of 5000.0 made using Credit Card.
Payment of 2000.0 made using UPI.