Having inheritance and polymorphism issues with Java

前端 未结 2 694
南旧
南旧 2021-01-26 14:56

I also need a overridden calclatefees method to calculate late fees for overdue movies.

 public class Action extends Movie {

    protected double latecost;
             


        
2条回答
  •  无人及你
    2021-01-26 15:33

    Currently this prints:

    overloaded - not overridden  NR 00
    overridden 
    

    Which is perfect. It demonstrates that constructors are treated specially. They all call the parent constructor first.

    You are therefore seeing the constructor of the Movie printing overloaded - not overridden NR 00, then the constructor of Action kicks in and prints overridden.

提交回复
热议问题