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

COMPUTER SOFTWARE APPLICATION - CITS




               }
           }
           // Subclass
           class Circle extends Shape {

               double radius;
               // Constructor
               Circle(String color, double radius) {
                   super(color); // Call superclass constructor
                   this.radius = radius;

               }
               void displayRadius() {
                   System.out.println(“Radius: “ + radius);
               }
           }



           // Main class
           public class ShapeDemo {
               public static void main(String[] args) {

                   // Create an instance of the Circle class
                   Circle circle = new Circle(“Red”, 5.0);


                   // Call the displayColor and displayRadius methods
                   circle.displayColor();
                   circle.displayRadius();

               }
           }


           Output:




























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