This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes overriden method question? urgent!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "overriden method question? urgent!!!" Watch "overriden method question? urgent!!!" New topic
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!!!
 
Similar Threads
Method overloading in the derived class
overloaded method with primitive (need help !)
method invocation through Inheritance.
Strict Definition of Override?
Inner Class method acess