Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why al can't access protected removeRange()? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why al can Watch "why al can New topic
Author

why al can't access protected removeRange()?

jimmy
Greenhorn

Joined: Nov 06, 2004
Posts: 18


( tags added, tabs replaced by spaces)
[ December 07, 2004: Message edited by: Barry Gaunt ]
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
The problem is that removeRange() is a protected method. It can only be accessed from within the same package (java.util) or by a subclass of ArrayList (which m is not).


Mike Gershman
SCJP 1.4, SCWCD in process
Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
To add on to what Mike said
Even though you subclass class m from java.util.ArrayList. With the present code, you still cannot access the protected method removeRange by using reference ArrayList al.


Protected members outside the package can be accessed using inheritance and not by reference.


Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
Anand Ko
Ranch Hand

Joined: Dec 03, 2003
Posts: 79
I didn't get the meaning of this sentence:

" Protected members outside the package can be accessed using inheritance and not by reference. "

Can you please explain on this.


Anand<br />SCJP 1.4, SCWCD 1.4, SCEA 5.0(1/3)
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Your class must extends the class that contains the protected method you are going to call. If you just include the class as a member, you are not allow to invoke the method, unless you are of the same package of that class.

Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why al can't access protected removeRange()?