This is Figure 9.11 Class BasePluscommissionEnployee Class BasePluscomnissionEnp
ID: 3802542 • Letter: T
Question
This is Figure 9.11
Class BasePluscommissionEnployee Class BasePluscomnissionEnployee (Fig. 9.9) extends the new version of class commis- sionEnployee with protected instance variables. BasePluscommissionEnployee objects inherit CommissionEmployee's protected instance variables firstNane, lastName, so cialSecurityNumber, grossSales and commissionRate-all these variables are now pro- tected members of BasePlusconmissionEmployee. As a result, the compiler does not generate errors when compiling line 45 of method earnings and lines 54-56 of method tostring. If another class extends this version of class BasePluscommissionEmployee, the new subclass also can access the protected members. I Fig. 9.9: BasePluscommissionEmployee.java 2 Base Plus CommissionEmployee inherits protected instance 3 variables from CommissionEmployee. 5 public class BasePlusCommissionEmployee extends CommissionEmployee 7 private double basesalary base salary per week Fig. 9.9 l BasePluscommissionEmployee inherits protected instance variables from Commission Employee. (Part I of 2) 380 Chapter 9 Object-Oriented Programming: inheritance 11 six-a rgument constructor 10 public Base PlusC firstName, String lastName ommissionEmployee(String String social Securit r, double gros sSales double commissionRate, double baseSalary) super(firstName, lastNane, socialSecurityNumber. 14 gross Sales commission Rate) 15 16 if basesalary is invalid throw exception if (baseSalary 0.0) throw new niegalArgumentExceptionC "Base salary must be 0.0"); this basesalary base salary 25 set base salary public void setBasesalaryCdouble basesalary) if (base salary 0.0) throw new niega ArgumentException( "Base salary must be 0-0"); this basesalary base salary return base salary public double getBasesalaryO base salary return
Explanation / Answer
Both will work in the same way.But the difference is that In 9.9 direct we are using its super classBase class CommissionedEmployee properties directly withount using any keywords.
But in 9.11 we are uisng the super class(Base class CommissionedEmployee ) methods by using the super keyword.The advantage of it is we no need to re-write the code of base class in sub class.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.