This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why al can't access protected removeRange()?

 
jimmy
Greenhorn
Posts: 18
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic