AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

attempting to assign weaker access privileges

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Madhur Ahuja
Guest





PostPosted: Mon Sep 20, 2004 12:41 pm    Post subject: attempting to assign weaker access privileges Reply with quote



Hello

This error normally occurs when a subclass overrides a method
but doesnt preserves the original access type like public.

However I am not able to understand what is the meaning of this
error especially what it means when it says *weaker*.

--
Madhur Ahuja [madhur<underscore>ahuja<at>yahoo<dot>com]

Homepage & other stuff
http://madhur.netfirms.com






Back to top
Paul Lutus
Guest





PostPosted: Mon Sep 20, 2004 6:16 pm    Post subject: Re: attempting to assign weaker access privileges Reply with quote



Madhur Ahuja wrote:

Quote:
Hello

This error normally occurs when a subclass overrides a method
but doesnt preserves the original access type like public.

However I am not able to understand what is the meaning of this
error especially what it means when it says *weaker*.

If you have a method in a parent class with a given access, and if you
override it while also giving it less general (example: private) access,
this error will result. This restriction exists because if access were
freely modifiable in subclasses, the entire idea of access control would
have no meaning - one could override the intent of the class designer along
with the methods.

http://www.janeg.ca/scjp/overload/overridingMethods.html

--
Paul Lutus
http://www.arachnoid.com


Back to top
Stefan Schulz
Guest





PostPosted: Mon Sep 20, 2004 9:16 pm    Post subject: Re: attempting to assign weaker access privileges Reply with quote



On Mon, 20 Sep 2004 11:16:59 -0700, Paul Lutus <nospam (AT) nosite (DOT) zzz> wrote:

Quote:
Madhur Ahuja wrote:

Hello

This error normally occurs when a subclass overrides a method
but doesnt preserves the original access type like public.

However I am not able to understand what is the meaning of this
error especially what it means when it says *weaker*.

If you have a method in a parent class with a given access, and if you
override it while also giving it less general (example: private) access,
this error will result. This restriction exists because if access were
freely modifiable in subclasses, the entire idea of access control would
have no meaning - one could override the intent of the class designer
along with the methods.

This is not actually a problem as long as you "widen" access. (e.g. make a
protected method public in a subclass). There are a few things you can not
do, however:

* publish private methods. Easy, since you can not access them from your
subclass. You _can_ however create a public method with the same signature.

* Narrow access. You can not make a public method protected in the
subclass.
Otherwise, the concept of Object Polymorphism would plainly not work. (An
instance of a subclass could not be assumed to have all the public methods
of the superclass)

* (For some strange reason) Modify return values. Yes, even if the new
Return value is a subclass of the old one, you must keep return types
equal. The rationale for this is not really apparent to me, but that's the
way it is

See you
Stefan

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.