Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added class and object in c++ #5082

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}