aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Protected variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Protected variable" Watch "Protected variable" New topic
Author

Protected variable

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Aug 28, 2000
Posts: 72
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

Joined: Nov 22, 2008
Posts: 18944

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

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Aug 28, 2000
Posts: 72
yes u r right.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Protected variable