-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f193fd
commit 3775c0e
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class and object | ||
|
||
class : 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 objects. | ||
|
||
object : An object is an instance of a class | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
class Student | ||
{ | ||
// there are 3 types of access modifiers they are private , public and protected | ||
// data members are private by default | ||
// we should specify it as public to access directly | ||
public: | ||
string name; | ||
int roll; | ||
int classno; | ||
void intro() | ||
{ | ||
cout << name << " " << roll << " " << classno; | ||
} | ||
}; | ||
int main() | ||
{ | ||
Student s1; | ||
s1.name = "sanu"; | ||
s1.classno = 12; | ||
s1.roll = 28; | ||
s1.intro(); | ||
|
||
// cout<<s1.name; | ||
// cout<<s1.roll; | ||
// cout<<s1.classno; | ||
return 0; | ||
} |