Hot Posts

Member’s Access Modifiers

Below is a summary of the principle characteristic of the access and non-access modifiers used in class declarations.


public


  • All classes regardless of package can access the member.


private:


  • Can only be accessed from within own class.
  • A private member is invisible to any code outside its own class.
  • A subclass cannot inherit a private member.
  • You can declare a member of the same name in a subclass but it is not overridden.
  • You can only override methods that can be inherited.


package default:


  • Can be accessed by classes of the same package.
  • Becomes private to classes in other packages.


protected:


  • Accessed by same package and by subclasses in other packages.
  • Respects the inheritance concept.
  • The inherited protected member becomes private to all other classes in the subclasses package.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: