<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Suraj&#039;s blog &#187; Access Modifiers</title>
	<atom:link href="http://www.surajshrestha.com.np/tag/access-modifiers/feed" rel="self" type="application/rss+xml" />
	<link>http://www.surajshrestha.com.np</link>
	<description>imagination more important than knowledge</description>
	<lastBuildDate>Sun, 08 Aug 2010 23:20:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Confusing Access Modifiers in Java Class and Members</title>
		<link>http://www.surajshrestha.com.np/java/confusing-access-modifiers-in-java-class-and-members.html</link>
		<comments>http://www.surajshrestha.com.np/java/confusing-access-modifiers-in-java-class-and-members.html#comments</comments>
		<pubDate>Tue, 31 Mar 2009 19:16:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Access Modifiers]]></category>

		<guid isPermaLink="false">http://www.surajshrestha.com.np/?p=3</guid>
		<description><![CDATA[Access Modifiers like Private, Protected, Public can confuse a novice programmer.  Access modifiers define where the class or method can be accessed in same class and another classes.
There are two levels of access control.
1.       At the Class level – ‘public’ or nothing(package-driven or default)
a.       If a class is defined as public, it can be accessed [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="font-family: Calibri; font-size: small;">Access Modifiers like Private, Protected, Public can confuse a novice programmer.<span style="mso-spacerun: yes;">  </span>Access modifiers define where the class or method can be accessed in same class and another classes.</span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="font-family: Calibri; font-size: small;">There are two levels of access control.</span></p>
<p class="MsoListParagraphCxSpFirst" style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;"><span style="font-family: Calibri; font-size: small;">1.</span><span style="font: 7pt &quot;Times New Roman&quot;;">       </span></span></span><span style="font-family: Calibri; font-size: small;">At the Class level – ‘public’ or nothing(package-driven or default)</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent: -0.25in; margin: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;"><span style="font-family: Calibri; font-size: small;">a.</span><span style="font: 7pt &quot;Times New Roman&quot;;">       </span></span></span><span style="font-family: Calibri; font-size: small;">If a class is defined as public, it can be accessed from all the classes anywhere (means from any package).</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent: -0.25in; margin: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;"><span style="font-family: Calibri; font-size: small;">b.</span><span style="font: 7pt &quot;Times New Roman&quot;;">      </span></span></span><span style="font-family: Calibri; font-size: small;">If a class is defined without any modifier, then it is package-driven that means, it is only visible inside the package in which it is defined.</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;"><span style="font-family: Calibri; font-size: small;">2.</span><span style="font: 7pt &quot;Times New Roman&quot;;">       </span></span></span><span style="font-family: Calibri; font-size: small;">At the Data Member level – ‘public’, ‘protected’, ‘private’ or nothing(package-driven or default)</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent: -0.25in; margin: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;"><span style="font-family: Calibri; font-size: small;">a.</span><span style="font: 7pt &quot;Times New Roman&quot;;">       </span></span></span><span style="font-family: Calibri; font-size: small;">If a data member of a class is defined as public as shown below, then it can be seen from anywhere.</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent: -1.5in; margin: 0in 0in 0pt 1.5in; mso-list: l0 level3 lfo1; mso-add-space: auto; mso-text-indent-alt: -9.0pt;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;"><span style="font: 7pt &quot;Times New Roman&quot;;">                                                               </span><span style="font-family: Calibri; font-size: small;">i.</span><span style="font: 7pt &quot;Times New Roman&quot;;">      </span></span></span><span style="font-family: Calibri; font-size: small;">public int a;</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent: -0.25in; margin: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;"><span style="font-family: Calibri; font-size: small;">b.</span><span style="font: 7pt &quot;Times New Roman&quot;;">      </span></span></span><span style="font-family: Calibri; font-size: small;">If a data member of a class is defined as protected, then it can be accessed only in its class and its child classes.</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent: -0.25in; margin: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;"><span style="font-family: Calibri; font-size: small;">c.</span><span style="font: 7pt &quot;Times New Roman&quot;;">       </span></span></span><span style="font-family: Calibri; font-size: small;">If a data member of a class is defined as private, then it can be only accessed in its class.</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent: -0.25in; margin: 0in 0in 0pt 1in; mso-list: l0 level2 lfo1; mso-add-space: auto;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;"><span style="mso-list: Ignore;"><span style="font-family: Calibri; font-size: small;">d.</span><span style="font: 7pt &quot;Times New Roman&quot;;">      </span></span></span><span style="font-family: Calibri; font-size: small;">If a data member is defined without any modifier, then it is package-driven. So, it is visible inside the package where it is defined.</span></p>
<p class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 1in; mso-add-space: auto;"><span style="font-family: Calibri; font-size: small;"> </span></p>
<p class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 1in; mso-add-space: auto;"><span style="font-family: Calibri; font-size: small;">The above rules defined for data member also applies for the methods of a class.</span></p>
<p class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 1in; mso-add-space: auto;"><span style="font-family: Calibri; font-size: small;">The following table summarizes the rules discussed above.</span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><strong style="mso-bidi-font-weight: normal;"></strong></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><strong style="mso-bidi-font-weight: normal;"><span style="font-size: small;"><span style="font-family: Calibri;">Access Levels</span></span></strong></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><strong style="mso-bidi-font-weight: normal;"><span style="font-size: small;"><span style="font-family: Calibri;">Modifier<span style="mso-tab-count: 1;">              </span>Class<span style="mso-tab-count: 1;">      </span><span style="mso-tab-count: 1;">                </span>Package<span style="mso-tab-count: 1;">               </span>Subclass<span style="mso-tab-count: 1;">               </span>World</span></span></strong></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="font-family: Calibri; font-size: small;">Public<span style="mso-tab-count: 1;">    </span><span style="mso-tab-count: 1;">                </span>Y<span style="mso-tab-count: 1;">              </span><span style="mso-tab-count: 1;">                </span>Y<span style="mso-tab-count: 1;">              </span><span style="mso-tab-count: 1;">                </span>Y<span style="mso-tab-count: 1;">              </span><span style="mso-tab-count: 1;">                </span>Y</span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="font-family: Calibri; font-size: small;">protected<span style="mso-tab-count: 1;">              </span>Y<span style="mso-tab-count: 1;">              </span><span style="mso-tab-count: 1;">                </span>Y<span style="mso-tab-count: 1;">              </span><span style="mso-tab-count: 1;">                </span>Y<span style="mso-tab-count: 1;">              </span><span style="mso-tab-count: 1;">                </span>N</span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="font-family: Calibri; font-size: small;">no modifier<span style="mso-tab-count: 1;">           </span>Y<span style="mso-tab-count: 1;">              </span><span style="mso-tab-count: 1;">                </span>Y<span style="mso-tab-count: 1;">              </span><span style="mso-tab-count: 1;">                </span>N<span style="mso-tab-count: 1;">             </span><span style="mso-tab-count: 1;">                </span>N</span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="font-family: Calibri; font-size: small;">private<span style="mso-tab-count: 1;">  </span><span style="mso-tab-count: 1;">                </span>Y<span style="mso-tab-count: 1;">              </span><span style="mso-tab-count: 1;">                </span>N<span style="mso-tab-count: 1;">             </span><span style="mso-tab-count: 1;">                </span>N<span style="mso-tab-count: 1;">             </span><span style="mso-tab-count: 1;">                </span>N</span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="font-family: Calibri; font-size: small;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;"> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.surajshrestha.com.np/java/confusing-access-modifiers-in-java-class-and-members.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->
