What are different types of access modifiers?

Author Topic: What are different types of access modifiers?  (Read 3186 times)

Offline chinmay.sahooTopic starter

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 2
  • Posts: 158
  • Karma: 0
    • We Helpline
What are different types of access modifiers?
« 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.

Offline damponting44

  • Trade Count: (0)
  • Hero Member
  • *****
  • Thank You 23
  • Posts: 621
  • Karma: 0
  • Gender: Male
    • Taxi app development
Re: What are different types of access modifiers?
« Reply #1 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.

Offline alpha_ace

  • Trade Count: (0)
  • Newbie
  • *
  • Thank You 0
  • Posts: 2
  • Karma: 0
Re: What are different types of access modifiers?
« Reply #2 on: 06-12-2018, 00:45:47 »
There are 3 types of access modifiers  are available


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.


Related Topics

  Subject / Started by Replies Last post
4 Replies
Last post 01-19-2012, 22:54:39
by cpaoutsourcing
1 Replies
Last post 07-28-2014, 02:03:44
by Siservices
3 Replies
Last post 02-28-2015, 02:42:43
by jannatul18
0 Replies
Last post 03-04-2015, 13:45:27
by jackmanson
2 Replies
Last post 10-25-2017, 04:10:06
by damponting44