aspose file tools*
The moose likes Beginning Java and the fly likes Protected Trouble Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Protected Trouble" Watch "Protected Trouble" New topic
Author

Protected Trouble

Arun Giridharan
Ranch Hand

Joined: Sep 30, 2010
Posts: 290

Hello!

Protected Access Specifier can used in another package if it gets extended right,so why can't i access in the following code.
[Please tell the reason(instead saying it's java rule)]


Thank you
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3858

Your example itself gives the reason. Members marked as protected are only inherited to the sub classes. You cannot use an instance of that class to access a protected member anywhere.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1


If this is possible. then what would be the difference between public and protected then ?


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3096
    
  33

Vijitha Kumara wrote:Your example itself gives the reason. Members marked as protected are only inherited to the sub classes. You cannot use an instance of that class to access a protected member anywhere.


Protected members are accessible within the same package.


Mohamed Sanaulla | My Blog
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3858

Protected members are accessible within the same package

Of course, my statement appeared that it isn't though the OP was referring to two different packages.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40032
    
  28
Yes, he is using two packages But it would have been nice to see imports which would not throw compiler errors.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Protected Trouble