Friday, August 5, 2022

COPY CONSTRUCTOR

 


#include <iostream>

using namespace std;

 

class Rectangle {

  private:

    double length;

    double breadth;

 

  public:

    Rectangle(double l, double b) {

      length = l;

      breadth = b;

    }

    Rectangle(Rectangle &obj) {

      length = obj.length;

      breadth = obj.breadth;

    }

 

 

    double calculateArea() {

      return length * breadth;

    }

};

 

int main() {

Rectangle obj1(10,6);

Rectangle obj2 = obj1; 

 

  cout << "Area of Rectangle 1: " << obj1.calculateArea();

  cout << "Area of Rectangle 2: " << obj2.calculateArea();

 

  return 0;

}

No comments:

Post a Comment

CONSTRUCTURE IN PARENT CLASS

class Parent {     public Parent()     {         System.out.println("Parent Constrcutor");     }              } class Child extend...