Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Q on Classes & SubClasses with protected members

Reply
Thread Tools

Q on Classes & SubClasses with protected members

 
 
Praveen
Guest
Posts: n/a
 
      11-20-2003
Hi..All,

Can someone please explain me this

"Access to protected members of the superclass would also be permitted
via any references of subclasses. The above restriction helps to ensure
that subclasses in package different from their superclass can only
access protected members of the superclass in their part of the
inheritance hierarchy".

Why is this restriction for class in a different package extending a
class from a different package?

This is from Khalid A Mughal's book.



Regards,

P

 
Reply With Quote
 
 
 
 
Woebegone
Guest
Posts: n/a
 
      11-21-2003

"Praveen" <> wrote in message
news:W0Yub.9088$ m...
> Hi..All,
>
> Can someone please explain me this
>
> "Access to protected members of the superclass would also be permitted
> via any references of subclasses. The above restriction helps to ensure
> that subclasses in package different from their superclass can only
> access protected members of the superclass in their part of the
> inheritance hierarchy".
>
> Why is this restriction for class in a different package extending a
> class from a different package?
>
> This is from Khalid A Mughal's book.
>
>
>
> Regards,
>
> P
>


If I understand correctly, the paragraph refers to "package private"
members -- members, declared with no access specifier, that appear public to
other members of the declaring class's package, but private to members from
external packages. This allows for some degree of coupling due to
implementation, but prevents implementation details from "leaking out" via
subclassing. It is common when implementing a component for example, that it
comprises multiple classes that must collaborate while presenting a unified
interface. The use of package private members allows the collaborating
classes to communicate with each other as necessary, but prevents clients
from writing code that depends on those members. Clients should program to
the component's interface only.

The stipulation about subclasses prevents using extension to circumvent the
encapsulation: say a component C is implemented as a collaboration of
classes A and B. In some cases, I could get access to implementation details
by writing my own subclass of A and installing it in C. For a concrete
example, imagine C being a logon dialog. In principle, I could subclass one
or more of the classes used by the dialog, creating a new version that
transmits to me the user's id and password.

That example might be a bit contrived, but there are many examples in Swing
of using package private access among classes that make up the components.

HTH!
Sean.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
protected members or explicit abstract classes? aidy Ruby 11 07-22-2008 05:40 AM
comparison of protected members vs abstract classes Sideswipe Java 6 09-20-2007 09:55 PM
Classes - Adding members to members Daz C++ 5 05-07-2006 09:25 AM
nested classes accessing inherited protected members of parents Mr Dyl C++ 2 12-01-2005 03:41 PM
Protected static members, abstract classes, object composition vs. subclassing Kevin Prichard Javascript 11 11-29-2005 01:33 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57