| Author |
overriden method question? urgent!!!
|
huanyu zhao
Greenhorn
Joined: Feb 22, 2001
Posts: 29
|
|
class BaseClass{ private float x=1.0f; private float getVar(){return x;} } class SubClass extends BaseClass{ private float x=2.0f; //insert code } what are true to override getVar()? A.float getVar(){ B.public float getVar(){ C.public double getVar(){ D.protected float getVar(){ E.public float getVar(float f){ SOMEBODY choose abd but i think getvar()in baseclass is private it can`t be seen from outside,so it can/need be overriden?? why?
|
[img]http://www.flyheart.com/bbs/attach/2002/11/07/59790-signature-embed.jpg[/img]
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
|
private methods are not inherited, and thus, they can not be overridden. This question is erroneous.
|
SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
|
 |
Deepali Pate
Ranch Hand
Joined: Mar 20, 2002
Posts: 114
|
|
But the private methods can be redeclared with the same name and return type and any modifier in subclass. This will not give any compile time or runtime error. Am i right???
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
|
right, but the question excplicitely asks about overriding. If you set the overriding thing aside, then all options are correct, since there are no constraints on which method can be declared within SubClass.
|
 |
Deepali Pate
Ranch Hand
Joined: Mar 20, 2002
Posts: 114
|
|
|
Thanks for clarification yes the ? clearly says override so it is an error.
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: overriden method question? urgent!!!
|
|
|