This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Protected Keywords - More Info about it Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Protected Keywords - More Info about it" Watch "Protected Keywords - More Info about it" New topic
Author

Protected Keywords - More Info about it

Nelly Verccety
Greenhorn

Joined: Feb 16, 2006
Posts: 8
I am analyzing java code using QJ-Pro and it comes with the next message:
Do not define protected members in classes that are not part of a named package. Anyone know what that means?

The line that is refering too is the following:
protected Panel getPanel() {return this;}

What do I need to know about protected keyword before I use it?
Nelly Verccety
Greenhorn

Joined: Feb 16, 2006
Posts: 8
Other thing, when is protected best used and where should be placed it so that its clear and will not break encapsulation?
Aum Tao
Ranch Hand

Joined: Feb 14, 2006
Posts: 210
Protected members are accessible in the same class or its subclasses.
If accessed from subclass , the instance should be of the class from where the protected member is being accessed or its subclass. The package may differ in this case.


SCJP 1.4 85%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Protected Keywords - More Info about it
 
Similar Threads
question on overloaded methods
protected variables
Why can't a class be declared private or protected
access modifier doesn't affect encapsulation?
Protected method in a packaged superclass not being called by subclass