#include<iostream>
#include<string>
using namespace std;
class Car {
string name;
string color;
public:
Car() {
cout << "constructor without paramas\n";
}
Car(string name, string color) {
cout << "constructor with params\n";
this->name = name;
this->color = color;
// *this.color = color; // this is a complex syntax so try to avoid it
}
void start() {
cout << "car has started..\n";
}
void stop() {
cout << "car has stopped..\n";
}
//Getter
string getName() {
return name;
}
};
int main() {
Car c0; // non-parameter
Car c1("maruti 800", "white"); // parameter
Car c2("fortuner", "white");
return 0;
}
No comments:
Post a Comment