Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package abstraction;
- public class abstractDemo
- {
- public static void main(String[] args)
- {
- Emp e = new Programmer();
- e.description();
- e.salary();
- e = new TesterEmp();
- e.description();
- e.salary();
- }
- }
- // OUTPUT
- //It is a Programmer
- //Salary of Programmer 25000
- //It is an employee
- //work as a Tester
- //Salary of Tester 35000
- package abstraction;
- abstract class Emp // no object can be generated of abstract class
- {
- public void description()
- {
- System.out.println("It is an employee");
- }
- abstract void salary(); // abstract function no body
- }
- class Programmer extends Emp
- {
- @Override
- public void description() // override description method
- {
- System.out.println("It is a Programmer");
- }
- @Override
- void salary() // the salary must be define in the child class
- {
- System.out.println("Salary of Programmer 25000");
- }
- }
- class TesterEmp extends Emp
- {
- public void description() // override description method
- {
- super.description(); // call description of parent class
- System.out.println("work as a Tester");
- }
- @Override
- void salary() // the salary must be define in the child class
- {
- System.out.println("Salary of Tester 35000 ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment