Given: 10. abstract public class Employee { 11. protected abstract double getSalesAmount(); 12. public double getCommision() { 13. return getSalesAmount() * 0.15; 14. } 15. } 16. class Sales extends Employee { 17. // insert method here 18. } Which two methods, inserted independently at line 17, correctly complete the Sales class? (Choose two.)

  1. A. double getSalesAmount() { return 1230.45; }

  2. B. public double getSalesAmount() { return 1230.45; }

  3. C. private double getSalesAmount() { return 1230.45; }

  4. D. protected double getSalesAmount() { return 1230.45; }


Correct Option: B,D
Explanation:

Explanation: To answer this question, we need to understand the concept of abstract classes and abstract methods in Java.

An abstract class is a class that cannot be instantiated on its own and must be subclassed. An abstract method is a method that is declared but does not have an implementation in the abstract class. Any subclass of the abstract class must provide an implementation for the abstract method.

In this code, the Employee class is an abstract class that has an abstract method named getSalesAmount(). The Sales class is a subclass of the Employee class and must provide an implementation for the getSalesAmount() method.

Option A) double getSalesAmount() { return 1230.45; } - This option is incorrect because the method needs to be declared as protected or public to provide implementation for the abstract method in the parent class.

Option B) public double getSalesAmount() { return 1230.45; } - This option is correct because it provides a public implementation for the abstract method in the parent class.

Option C) private double getSalesAmount() { return 1230.45; } - This option is incorrect because a private method cannot override a method in the parent class.

Option D) protected double getSalesAmount() { return 1230.45; } - This option is correct because it provides a protected implementation for the abstract method in the parent class.

Therefore, options B and D are the correct answers.

Find more quizzes: