| Author |
Overriding / Overloading method???
|
Heinz Wu
Greenhorn
Joined: May 04, 2004
Posts: 5
|
|
Could anyone tell me that if I am given the following: class Foo { String doStuff(int x) {return "hello";} } Is it legal to put protected String doStuff(int x) {return "Hello";} in a subclass of Foo? my answer is illegal, because overriding method must not have a more trstrictive access modifier. Am I right or wrong? Thanks [ May 04, 2004: Message edited by: Heinz Wu ] [ May 04, 2004: Message edited by: Heinz Wu ] [ May 04, 2004: Message edited by: Heinz Wu ]
|
 |
Peng Fan
Ranch Hand
Joined: May 04, 2004
Posts: 35
|
|
hi,Heinz Wu: i do not think the answer you got is correct,however those ideas which makes you reduced the conclusion are seemingly wrong.what make you to be caught in a dilemma,i think,is you can not make a clear distinguish between the access modifier default and protected,default has package access,protected have subclass access as well as package access.Do i made myself clear?
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
you can not make a clear distinguish between the access modifier default and protected,default has package access,protected have subclass access as well as package access But a very clear distinction between them exists - default is more restrictive. You said so yourself. So, Heinz, you got default and protected backwards. A subclass could modify the overridden method with protected. A good way to determine answers to questions like these is to simply write a simple example program and see what happens when compiling and running it. [ May 04, 2004: Message edited by: Dirk Schreckmann ]
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
 |
|
|
subject: Overriding / Overloading method???
|
|
|