Page 191 - CTS - CSA TP - Volume 2
P. 191

COMPUTER SOFTWARE APPLICATION - CITS




           3  Main Class (MethodOverrideBasicExample):
              •  Creates an instance of the Car class.
              •  Calls the overridden method displayInfo, which outputs specific information for a car.
              •  Calls the additional method startEngine, which is specific to the Car class.
           In  this  basic  example,  the  displayInfo  method  is  overridden  in  the  Car  class  to  provide  specific  information
           for a car. Method overriding allows the subclass to provide its own implementation of a method defined in the
           superclass. Instances of the subclass can be treated as instances of the superclass, providing flexibility in coding
           and enhancing code reusability.
           Output:








































































                                                           176
                                CITS : IT & ITES - Computer Software Application - Exercise 112
   186   187   188   189   190   191   192   193   194   195   196