Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,855 questions

51,776 answers

573 users

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 164 views
1 answer 154 views
1 answer 151 views
1 answer 137 views
1 answer 137 views
137 views asked Apr 1, 2018 by avibootz
6 answers 335 views
335 views asked Apr 25, 2017 by avibootz
...