Access levels

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(New page: This is a brief description of the different access levels available in commonly used languages and what encapsulation boundaries they provide. ==Java== * private - Any code in this clas...)
 
Line 2: Line 2:
  
 
==Java==
 
==Java==
* private - Any code in this class
+
* <tt>private</tt> - Any code in this class
* package - private + any other class in this package (This is the default access level)
+
* package level - private + any other class in this package (This is the default access level)
* protected  - package + any subclasses
+
* <tt>protected</tt> - package + any subclasses
* public - Open access
+
* <tt>public</tt> - Open access
  
 
==C#==
 
==C#==
* private - Any code in this class (or struct)
+
* <tt>private</tt> - Any code in this class (or struct)
* protected - private + any subclass
+
* <tt>protected</tt> - private + any subclass
* internal - private + any other class (or struct) in this assembly
+
* <tt>internal</tt> - private + any other class (or struct) in this assembly
* protected internal - private + any subclass + any other class (or struct) in this assembly
+
* <tt>protected internal</tt> - private + any subclass + any other class (or struct) in this assembly
* public - open access
+
* <tt>public</tt> - open access
  
 
==C++==
 
==C++==
* private - Any code in this class
+
* <tt>private</tt> - Any code in this class
* protected - private + any subclasses
+
* <tt>protected</tt> - private + any subclasses
* public - open access
+
* <tt>public</tt> - open access
 
C++ doesn't have a package level access equivalent, but it can give access to others using the 'friend' keyword.
 
C++ doesn't have a package level access equivalent, but it can give access to others using the 'friend' keyword.

Revision as of 23:31, 29 August 2009

This is a brief description of the different access levels available in commonly used languages and what encapsulation boundaries they provide.

Java

  • private - Any code in this class
  • package level - private + any other class in this package (This is the default access level)
  • protected - package + any subclasses
  • public - Open access

C#

  • private - Any code in this class (or struct)
  • protected - private + any subclass
  • internal - private + any other class (or struct) in this assembly
  • protected internal - private + any subclass + any other class (or struct) in this assembly
  • public - open access

C++

  • private - Any code in this class
  • protected - private + any subclasses
  • public - open access

C++ doesn't have a package level access equivalent, but it can give access to others using the 'friend' keyword.

Personal tools