Rahmadnet

abstraction Asigment

Feb 13th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. package abstraction;
  2.  
  3. public class abstractDemo
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         Emp e = new Programmer();
  8.         e.description();
  9.         e.salary();
  10.        
  11.         e = new TesterEmp();
  12.         e.description();
  13.         e.salary();
  14.     }
  15. }
  16.  
  17. // OUTPUT
  18.  
  19. //It is a Programmer
  20. //Salary of Programmer 25000
  21. //It is an employee
  22. //work as a Tester
  23. //Salary of Tester 35000   
  24.  
  25. package abstraction;
  26.  
  27. abstract class Emp // no object can be generated of abstract class
  28. {
  29.     public void description()
  30.     {
  31.         System.out.println("It is an employee");
  32.     }
  33.    
  34.     abstract void salary(); // abstract function no body
  35. }
  36.  
  37. class Programmer extends Emp
  38. {
  39.     @Override
  40.     public void description() // override description method
  41.     {
  42.         System.out.println("It is a Programmer");
  43.     }
  44.  
  45.     @Override
  46.     void salary() // the salary must be define in the child class
  47.     {
  48.         System.out.println("Salary of Programmer 25000");
  49.        
  50.     }
  51. }
  52.  
  53. class TesterEmp extends Emp
  54. {
  55.     public void description() // override description method
  56.     {
  57.         super.description(); // call description of parent class
  58.         System.out.println("work as a Tester");
  59.     }
  60.  
  61.     @Override
  62.     void salary()  // the salary must be define in the child class
  63.     {
  64.         System.out.println("Salary of Tester 35000  ");
  65.        
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment