I am fairly new to Java Inheritance and I don't understand why I have an error? -
here problem:
write class marketer accompany other law firm classes described in chapter. marketers make $50,000 ($10,000 more general employees) , have additional method called advertise prints "act now, while supplies last!" make sure interact employee superclass appropriate.
the code far:
public class marketer extends employee { public marketer() { setbasesalary(super.getsalary() + 10000.0); } public void advertise() { system.out.println("act now, while supplies last!") ; } } this output should be:
50000.0
75535.0
act now, while supplies last!
there file extension called employee.java on following site code above follows: http://practiceit.cs.washington.edu/problem.jsp?id=1324
so have far, printed out every expected outcome except 75535.0! did go wrong?? when ran code, said (for error had received on 75535.0 part):
(change base salary $65535.00)
because output 65535.0, 10000 less answer supposed be.
i can't seem find error since started these inheritance kind of things in java, still unfamiliar it. thank if can me understand messed up.
here's what's happening:
create marketer, calls employee's constructor , instance initialization. sets basesalary 40,000. code in markerter constructor runs , sets basesalary 50,000. test driver calls setbasesalary value of 65535.0, overwriting initial set.
your code isn't interacting employee class. comment in employee.java says code isn't supposed use, call, or modify values below. 1 of basesalary variable, , modifying in marketer constructor. once test driver changes value, class has no way compute changed salary marketer.
you shouldn't call setbasesalary in constructor. instead, override getsalary in marketer, , use getsalary method employee in own class.
Comments
Post a Comment