TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Monday 24 August 2020

Base Access Control in C++ | Example Of Base Access Control in C++ | Base Access Control in C++ In Hindi

Base Access Control In C++


Access modifiers in C++ class defines the access control rules. C++ has 3 new keywords introduced, namely,

1.    public

2.    private

3.    protected

These access modifiers are used to set boundaries for availability of members of class be it data members or member functions

Access modifiers in the program, are followed by a colon. You can use either one, two or all 3 modifiers in the same class to set different boundaries for different class members. 


image of base access control in c++
Fig: Base Access Control In C++



1.
Public

Public, means all the class members declared under public will be available to everyone. The data members and member functions declared public can be accessed by other classes too. The key members must not be declared public.

 

Syntax:

class public access

{

public:

int x;

void display();

}


2.Private

Private keyword, means that no one can access the class members declared private, outside that class. If someone tries to access the private members of a class, they will get a compile time error. By default class variables and member functions are private.


Syntax:

class private access

{

private:

int x;

void display();

}


3.Protected

Protected, is the last access specifier, and it is similar to private, it makes class member inaccessible outside the class. But they can be accessed by any subclass of that class.

Syntax:

class protected access

{

protected:

int x;

void display();

}


Program:

#include<iostream.h>

#include<conio.h>

class bca

{

public:

private:

protected:

};

class abc: private bca

{

public:

void output()

{

cout<<”base class created”;

}

public:

void show()

{

cout<<”derived class created”;

}

};

void main()

{

abc ob;

ob.output();

ob.show();

getch();

}


Output:

Base class created

Derived class created

 

No comments:

Post a Comment