From 0d10236124e6bf45c626e4b3a7d825234b97bc1f Mon Sep 17 00:00:00 2001 From: Neeraj Nagar <30791552+neerajnagar26@users.noreply.github.com> Date: Tue, 11 Mar 2025 14:58:15 -0400 Subject: [PATCH] made constructor and displayInfo as public --- oop/cpp/classesandobjects/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/oop/cpp/classesandobjects/README.md b/oop/cpp/classesandobjects/README.md index 7fbed3a..a70dade 100644 --- a/oop/cpp/classesandobjects/README.md +++ b/oop/cpp/classesandobjects/README.md @@ -24,6 +24,7 @@ class Car { string model; int year; + public: // Constructor Car(string color, string make, string model, int year) { this->color = color; @@ -39,7 +40,7 @@ class Car { cout << "Car Year: " << year << endl; cout << "Car Color: " << color << endl; } -} +}; ``` - **Attributes**: The class `Car` has four attributes that describe its state: `color`, `make`, `model`, and `year`. - **Constructor**: The constructor `Car(string color, string make, string model, int year)` initializes new objects of the class. @@ -65,9 +66,11 @@ int main() { car1.displayInfo(); cout << "-----------------"; car2.displayInfo(); + + return 0; } ``` 1. **Instantiation**: The `Car` constructor is used to create an object, which allocates memory for it. 2. **Initialization**: The constructor (`Car`) initializes the object state with given parameters. -3. **Reference**: The object is referenced through a variable (`car1`, `car2`) that points to its memory location. \ No newline at end of file +3. **Reference**: The object is referenced through a variable (`car1`, `car2`) that points to its memory location.