This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overriden method question? urgent!!!

 
huanyu zhao
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
private methods are not inherited, and thus, they can not be overridden. This question is erroneous.
 
Deepali Pate
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for clarification yes the ? clearly says override so it is an error.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic