• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why al can't access protected removeRange()?

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


( tags added, tabs replaced by spaces)
[ December 07, 2004: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic