-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path30Classes Objects.cpp
36 lines (27 loc) · 1.16 KB
/
30Classes Objects.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include<conio.h>
using namespace std;
/***********************
C++ is an object-oriented programming language.
Everything in C++ is associated with classes and objects, along with its attributes and methods. For example: in real life, a car is an object. The car has attributes, such as weight and color, and methods, such as drive and brake.
Attributes and methods are basically variables and functions that belongs to the class. These are often referred to as "class members".
A class is a user-defined data type that we can use in our program, and it works as an object constructor, or a "blueprint" for creating obj
******************/
//To create a class, use the class keyword:-
class MyClass { // The class
public: // Access specifier
int myNum; // Attribute (int variable)
string myString; // Attribute (string variable)
};
int main() {
//Create an Object
MyClass myObj; // Create an object of MyClass
// Access attributes and set values
myObj.myNum = 15;
myObj.myString = "Prince ferozepuria";
//print values
cout << myObj.myNum << "\n";
cout << myObj.myString;
return 0;
}
//Navjot Singh Prince