Skip to content

Commit

Permalink
added class and object in c++
Browse files Browse the repository at this point in the history
  • Loading branch information
Santanujana2001 committed Oct 2, 2023
1 parent 6f193fd commit 3775c0e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Add Code Here/C++/OOPS/Classandobj.cpp
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;
}

0 comments on commit 3775c0e

Please sign in to comment.