Quick Guide For OOP in C++ - LeetCode Discuss
Quick Guide For OOP in C++ - LeetCode Discuss
New
Explore Problems Interview Contest Discuss Store Premium
brand = x;
model = y;
year = z;
}
};
Just like functions, constructors can also be defined outside the class.
class Car {
public:
string brand;
string model;
int year;
// Constructor declaration
Car(string x, string y, int z);
};
Access Specifiers
KEY Points: By default class are private if you don't specify an access specifier
Encapsulation
KEY Points: To access a private attribute, use public "get" and "set" methods
class Employee {
private:
int salary;
public:
void setSalary(int s) {
salary = s;
}
int getSalary() {
return salary;
https://leetcode.com/discuss/study-guide/3293285/Quick-Guide-for-OOP-in-C%2B%2B 1/1