Why make a field protected when it is not encouraged to access itdirectly?

?

-

Viewing the source code for JComboBox I see multiple documentation of
the such :

/**
* This protected field is implementation specific. Do not access
directly or override. Use the accessor methods instead.


Why do sun make the field protected if they encourage others to use the
accessor methods? Is it for the sake of true OOP to make the field
protected?
 
H

HK

- said:
/**
* This protected field is implementation specific. Do not access
directly or override. Use the accessor methods instead.


Why do sun make the field protected if they encourage others to use the
accessor methods? Is it for the sake of true OOP to make the field
protected?

If it were private, subclasses implemented by SUN
could not use it. Hence it has to be protected. On the other
hand, if you make a subclass, all they promise for
future versions is stability of the accessor methods.

Harald.
 
?

-

HK said:
If it were private, subclasses implemented by SUN
could not use it. Hence it has to be protected. On the other
hand, if you make a subclass, all they promise for
future versions is stability of the accessor methods.

I forgot to mention that on top of making the fields protected that same
class also has public accessor methods for that fields. Isn't that
redundant?
 
?

-

- said:
I forgot to mention that on top of making the fields protected that same
class also has public accessor methods for that fields. Isn't that
redundant?

Nmind. I just grasp it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top