C++ PROGRAM TO SHOW THE DIFFERENCE OF PUBLIC AND PRIVATE ACCESS MODIFIERS | CODE WITH SHARAD

C++ PROGRAM TO SHOW THE DIFFERENCE OF PUBLIC AND PRIVATE ACCESS MODIFIERS

Written by Sharad Raj on 24th of May, 2018

BASIC OOPS PROGRAMS   C++ LANGUAGE PROGRAMS

PROGRAM CODE

**private**
 - Only the current class will have access to the field or method.


**protected**
 - Only the current class and subclasses (and sometimes also same-package classes) of this class will have access to the field or method.


**public**
 - Any class can refer to the field or call the method.


**SYNTAX:-**

#include<iostream>
using namespace std;
class tenth
{
private:
string name;
public:
void setname(string x)
{
name = x;
}
string getname()
{
return name;
}
};
int main()
{
tenth ob1,ob2;
ob1.setname("hello");
cout<<ob1.getname();
}


Comments


Contact