Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made constructor and displayInfo as public #89

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions oop/cpp/classesandobjects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Car {
string model;
int year;

public:
// Constructor
Car(string color, string make, string model, int year) {
this->color = color;
Expand All @@ -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.
Expand All @@ -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.
3. **Reference**: The object is referenced through a variable (`car1`, `car2`) that points to its memory location.