Page 99 - CITS - CSA - TP (Volume 2) - Hindi
P. 99

कं  ूटर सॉ वेयर ए ीके शन - CITS




                      length = l;

                      width = w;
                  }
                  // Method to calculate area of the rectangle

                  double calculateArea() {
                      return length * width;
                  }

                  // Method to calculate perimeter of the rectangle
                  double calculatePerimeter() {
                      return 2 * (length + width);

                  }
              }
              // Main class to demonstrate the usage of Rectangle class

              public class RectangleDemo {
                  public static void main(String[] args) {

                      // Create an object of Rectangle class
                      Rectangle rect1 = new Rectangle(5.0, 3.0);
                      // Accessing object properties and methods

                      System.out.println(“Length: “ + rect1.length);
                      System.out.println(“Width: “ + rect1.width);
                      System.out.println(“Area: “ + rect1.calculateArea());

                      System.out.println(“Perimeter: “ + rect1.calculatePerimeter());
                  }
              }

           आउटपुट :






























                                                           85

                                   CITS : IT & ITES - कं  ूटर सॉ वेयर ए ीके शन - अ ास 94
   94   95   96   97   98   99   100   101   102   103   104