Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Protected Keywords - More Info about it

 
Nelly Verccety
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic