File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes protected access modifier Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "protected access modifier" Watch "protected access modifier" New topic

protected access modifier

devika cha

Joined: Dec 17, 2003
Posts: 23
A protected instance variable can be accessed by subclass in same package or from different package by inheritance.

My question is how to access protected instance var in the subclass that is in same package .
thank you.
[ edited to preserve formatting using the [code] and [/code] UBB tags and to format the code -ds ]
[ January 09, 2004: Message edited by: Dirk Schreckmann ]
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33124

You have the right idea. In the example you posted, the dep class is not a sublcass of the Test class. It is extending a class called ThreadTest.

[ January 08, 2004: Message edited by: Jeanne Boyarsky ]

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

protect from what?
I agree. Here's the link:
subject: protected access modifier
It's not a secret anymore!