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

diff between protectec and none("package access")

 
sunitha reghu
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i write class Employee {
String name;
}, means it is accessible within the package rt.
so wat is the difference if i write protected String name
class Employee{
protected String name;}
both means members are accessible inside the package rt?
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, both are accessible in your package, BUT protected also gives subclasses of Employee access to it.
If you don't specify the access modifier, then it is considered "default" access and subclasses can't access it.
 
sunitha reghu
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic