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

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




              class Rectangle extends Shape {
                  private double length;

                  private double width;
                  // Constructor
                  public Rectangle(double length, double width) {

                      this.length = length;
                      this.width = width;
                  }

                  // Implementation of abstract method
                  @Override

                  public double calculateArea() {
                      return length * width;
                  }

              }
              // Main class
              public class AbstractClassExample {

                  public static void main(String[] args) {
                      // Create instances of concrete classes
                      Circle circle = new Circle(5.0);

                      Rectangle rectangle = new Rectangle(4.0, 6.0);


                      // Call abstract and concrete methods

                      circle.displayArea();    // Calls abstract method implementation in Circle
                      rectangle.displayArea(); // Calls abstract method implementation in Rectangle
                  }

              }
             ीकरण:

           1  ए   ै   ास (आकार):
              •   काया  यन के  िबना एक ए   ै  िविध calculateArea() का िववरण देता है।
              •   एक ठोस िविध displayArea() को प रभािषत करता है जो ए   ै  िविध को कॉल करता है।

           2  ठोस वग  (वृ  और आयत):
              •   ए   ै   ास आकार का िव ार कर ।
              •   ए   ै  िविध calculateArea() के  िलए काया  यन  दान कर ।

           3  मेन  ास (AbstractClassExample):
              •   ठोस वग  के  उदाहरण बनाता है।
              •   ए   ै  और ठोस िविधयों को कॉल करने का  दश न करता है।





                                                           164

                                  CITS : IT & ITES - कं  ूटर सॉ वेयर ए ीके शन - अ ास 110
   173   174   175   176   177   178   179   180   181   182   183