Hi, When I try to access the protected method removeRange() from the Vector class, I get a compilation error even though my class is a subclass of Vector. Why is this happening or am I doing smth wrong? ( I though it was possible to access protected members from a subclass) Many thanks...
You create a subclass, BUT you access the vector not via the subclass mechanism (which would be this.removeRange()) rather you access the vector instance through the normal method invocation (aVector.removeRange() ). The vector you are acessing via aVector is not of type RemRange (i.e. you are not accessing your superclass).
Your class RemRange is implemented wrongly as well (therefor you get your problem, it is implemented as a wrapper around a vector and not as a subclass).
Peter. [ August 19, 2002: Message edited by: Peter Reinhardt ]
SCJP 1.2, SCJD, SCEA, IBM 484, Weblogic 7
Joined: Jan 08, 2002
thanks Peter, that's fixed it
Joined: Jun 06, 2002
I think you are confused between "is a Vector" and "has a Vector". You are extending Vector but you also have a Vector as a member of your class. Do you really want to do both? If you are extending Vector, you can call a protected method on this, but you can't call a protected method on a Vector that happens to be a member of this. I don't know why Java chose to declare removeRange protected at all, since it seems to be a useful method. You might just want to declare your subclass to override removeRange with a public method that does the same thing:
[ August 19, 2002: Message edited by: Ron Newman ] [ August 19, 2002: Message edited by: Jim Yingst ]