How to use abstract class in Java

2 Answers

0 votes
abstract class Employee {
    abstract float getSalary();
}

class Developer extends Employee{
    private final float salary;
    public Developer(float _salary) {
        salary = _salary;
    }
    float getSalary() {
        return salary;
    }
}

class Scientist extends Employee {
    private final float salary;
    public Scientist(float _salary) {
        salary = _salary;
    }
    float getSalary() {
        return salary;
    }
}
 
public class JavaApplication {
    public static void main(String[] args) {
        Developer d = new Developer(12000);
        Scientist s = new Scientist(10000);
         
        System.out.println("Salary of developer : " + d.getSalary());
        System.out.println("Salary of scientist : " + s.getSalary());    
    }
}
 
 
 
/*
run:
 
Salary of developer : 12000.0
Salary of scientist : 10000.0
 
*/

 

 



answered Jul 4, 2017 by avibootz
edited May 4, 2024 by avibootz
0 votes
abstract class AC { 
      abstract void run();  
}
public class Test extends AC {  
    void run() {
        System.out.println("class Test extends AC - run()");
    }  
    public static void main(String args[]) {  
        AC obj = new Test();  
         
        obj.run();  
    }  
} 
 
 
/*
run:
 
class Test extends AC - run()
 
*/

 



answered May 4, 2024 by avibootz

Related questions

1 answer 205 views
1 answer 203 views
1 answer 176 views
1 answer 171 views
1 answer 164 views
164 views asked Apr 1, 2018 by avibootz
6 answers 375 views
375 views asked Apr 25, 2017 by avibootz
...