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

why al can't access protected removeRange()?

 
jimmy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


( tags added, tabs replaced by spaces)
[ December 07, 2004: Message edited by: Barry Gaunt ]
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Jay Pawar
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anand Ko
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic