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

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




                      this.width = width;
                  }

                  // Method to calculate the area of the rectangle
                  double calculateArea() {
                      return length * width;

                  }
              }
              public class RectangleDemo {

                  public static void main(String[] args) {
                      // Creating an instance of Rectangle using the parameterized constructor

                      Rectangle rectangle = new Rectangle(5.0, 3.0);


                      // Displaying the area of the rectangle
                      System.out.println(“Area of the rectangle: “ + rectangle.calculateArea());

                  }
              }



           आउटपुट:














             ीकरण:
           •   इस  ो ाम म , हम लंबाई और चौड़ाई िवशेषताओं के  साथ एक  ास Rectangle प रभािषत करते ह ।

           •   हम Rectangle वग  के  िलए एक पैरामीटराइ ड क   र  दान करते ह , जो पैरामीटर के   प म  पा रत मानों के  साथ लंबाई और चौड़ाई
              िवशेषताओं को आरंभ करता है।

           •   मु  िविध म , हम पैरामीटराइ ड क   र का उपयोग करके  आयत वग  का एक उदाहरण बनाते ह , िजसम  लंबाई और चौड़ाई के  िलए िविश
              मान पास िकए जाते ह ।

           •  आयत के   े फल की गणना और  दिश त करने के  िलए हम Rectangle वग  की calculateArea िविध का उपयोग करते ह ।

           टा  3:  ू ड ट  ास म  पैरामीटराइ ड कं    र

              // Student Class  using Parameterized Constructor

              class Student {
                  String name;

                  int age;


                                                           114

                                   CITS : IT & ITES - कं  ूटर सॉ वेयर ए ीके शन - अ ास 97
   123   124   125   126   127   128   129   130   131   132   133