Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2008

Tip: Looking for answers? Try searching our database.

why a class can't access protected method from another class in the     same package,the method is interited from the ohtner class from differnt     package?

Thread view: 
junzhang1983@gmail.com - 26 Jan 2008 06:33 GMT
package XX;
class A
{
  protected void kk ();
}

package YY;
import XX.A;

class B extends A
{

}

package YY;
class C
{
  public void zz()
   {
       kk();   //why can call B.kk()????
   }
}

but if we modify as below:
package YY;
import XX.A;

class B extends A
{
     protected void kk ()
   {
           super.kk();
   }
}

why  above modify can success?
3ks
Hal Rosser - 26 Jan 2008 07:47 GMT
> package XX;
> class A
[quoted text clipped - 18 lines]
>    }
> }

_________
Because protected keyword gives access to subclasses and other members of
the same package.
And class C is not a subclass and not in package XX.

> but if we modify as below:
> package YY;
[quoted text clipped - 10 lines]
> why  above modify can success?
> 3ks
 Because B is a subclass of A
Lew - 26 Jan 2008 17:18 GMT
<junzhang1983@gmail.com> wrote ...
>> package XX;
>> class A
[quoted text clipped - 18 lines]
>>    }
>> }

This will not compile.  Why does the comment refer to B.kk()?  Class B is not
involved in the C invocation at all.  C does not have a method kk().

Signature

Lew

Roedy Green - 28 Jan 2008 02:09 GMT
>why  above modify can success?

two things. Please use standard caps conventions when you write code,
especially lower case package names. See
http://mindprod.com/jgloss/codingconventions.html

It makes your code look extremely weird to an eye accustomed to
conformant code.

Next read up on what the various scopes are supposed to do.

See http://mindprod.com/jgloss/scope.html
http://mindprod.com/jgloss/protected.html
Signature

Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.