Skip to content

Commit 96448c7

Browse files
committed
basic OOP
1 parent 585d46b commit 96448c7

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

.gitignore.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.exe

basic.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include<iostream>
2+
3+
using namespace std;
4+
5+
class human{
6+
7+
public:
8+
9+
string name;
10+
void introduce();
11+
12+
13+
};
14+
15+
16+
//scope resolution operator-used to define the class methods outside the class
17+
void human :: introduce()
18+
{
19+
cout<<"Hello"<<" " <<human :: name <<endl;
20+
}
21+
22+
23+
int main ()
24+
{
25+
human obj1;
26+
obj1.name="Anish";
27+
obj1.introduce();
28+
29+
human *obj2 = new human; //pointer method of creating an dynamic object stored in HEAP section of memory
30+
obj2->name="Mrinal";
31+
obj2->introduce();
32+
cout<<obj2; //displays the address of memory in heap
33+
34+
return 0;
35+
}

basic.exe

2.58 MB
Binary file not shown.

classBasic.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<iostream>
2+
3+
using namespace std;
4+
5+
class Human {
6+
string name;
7+
8+
};
9+
10+
string Human :: name="Anish";
11+
12+
13+
int main()
14+
{
15+
Human anish;
16+
anish.name;
17+
18+
return 0;
19+
}

0 commit comments

Comments
 (0)