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

COMPUTER SOFTWARE APPLICATION - CITS




           Explanation:
           •  In this program, we have a superclass Shape and a subclass Circle.

           •  The Shape class has an attribute color, and a method displayColor() to display the color.
           •  The Circle class extends the Shape class and adds its own attribute radius and a method displayRadius()
              to display the radius.
           •  In the Circle constructor, super(color) is used to call the superclass constructor and initialize the inherited
              attribute.
           •  In the main method, we create an instance of the Circle class with a color and radius, and call the displayColor()
              and displayRadius() methods.
           These examples  demonstrate how superclasses  and subclasses  are used in Java to create hierarchical
           relationships, promote code reusability, and achieve inheritance. The subclass inherits attributes and methods
           from its superclass and can also add its own unique attributes and behaviors. This allows for code organization
           and simplifies the maintenance and extension of software systems.

           Demonstrate writing JAVA programs to :






























































                                                           138
                                CITS : IT & ITES - Computer Software Application - Exercise 100
   148   149   150   151   152   153   154   155   156   157   158