Seo Forum

Coding & Programming => Programming Forum => Topic started by: chinmay.sahoo on 01-25-2016, 02:07:24

Title: What are different types of access modifiers?
Post by: chinmay.sahoo on 01-25-2016, 02:07:24
public: Any thing declared as public can be accessed from anywhere. private: Any thing declared as private can’t be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages. default modifier : Can be accessed only to classes in the same package.
Title: Re: What are different types of access modifiers?
Post by: damponting44 on 10-25-2017, 04:08:13
The access to classes, constructors, methods and fields are regulated using access modifiers i.e. a class can control what information or data can be accessible by other classes. To take advantage of encapsulation, you should minimize access whenever possible.
Title: Re: What are different types of access modifiers?
Post by: alpha_ace on 06-12-2018, 00:45:47
There are 3 types of access modifiers  are available

Public
Private
Protected

Public: 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 public members of a class can be accessed from anywhere in the program using the direct member access operator (.) with the object of that class.

Private: The class members declared as private can be accessed only by the functions inside the class. They are not allowed to be accessed directly by any object or function outside the class. Only the member functions or the friend functions are allowed to access the private data members of a class.

Protected: Protected access modifier is similar to that of private access modifiers, the difference is that the class member declared as Protected are inaccessible outside the class but they can be accessed by any subclass(derived class) of that class.