From: Dossy Date: 2002-05-23T12:02:46+09:00 Subject: Re: confused about access control On 2002.05.23, Mike Campbell wrote: > > > "Protected methods can be invoked only by objects of the defining > > > class and its subclasses." > > > > > > Well, foo is an instance of String, which is the class that defines > > > the undot! method, so why does this not work? > > > > foo is an instance of String, but Foo isn't a subclass of String. > > Even if Foo were a subclass of String, foo.undot! is trying to publically > > access the undot! method. > > > foo (lowercase) IS a[n instance of] String, right? So why can't an > instance of String call a protected method of String? I don't think > the enclosing "Foo" class definition is relevant here, is it? Stop saying "call" and instead say "send a message" because that's where the confusion arises. An object will only receive messages for protected methods from objects of the same type or its decendants. In the code example, the sending object is NOT an instance of String, it's an instance of Foo which is not an instance of String or a descendant of String. -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)