• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Protected variable

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
I would like to know If variable A is Protected of class ABC of package 1 then can other class of same package 1 and also classes of package 2 access protected variable A?
thanks in advance for help!
ADS
 
Sunita Vontel
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what I know
All the subclasses of Package A and Package B or any ither package(provided they extend this class) can access the protected variable.
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator

Hi ADS,
The scope of the protected variable is for
all classes within the package and all subclasses
( it does not matter in which package subclasses are located )in which protected var is defined.It means protected var is available for all subclasses and for all other classes in the same package. Hope this clears yor doubt!!!

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
HI Jaypii & Sunita,
Thanks for ur response.
What I understood that no matter what package, protected variables are accessed by all classes and sub classes of any package who extend the class of protected variable.
May I right?
Please confirm my clarification
Thanks a bunch!
ADS

Originally posted by ADS:
I would like to know If variable A is Protected of class ABC of package 1 then can other class of same package 1 and also classes of package 2 access protected variable A?
thanks in advance for help!
ADS

 
Sunita Vontel
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes u r right.
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
HI SUNITA,
THANKS A LOT!
ADS

Originally posted by ADS:
HI Jaypii & Sunita,
Thanks for ur response.
What I understood that no matter what package, protected variables are accessed by all classes and sub classes of any package who extend the class of protected variable.
May I right?
Please confirm my clarification
Thanks a bunch!
ADS


 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic