This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Java in General and the fly likes Static binding question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Static binding question" Watch "Static binding question" New topic
Author

Static binding question

Oceana Wickramasinghe
Ranch Hand

Joined: Mar 02, 2011
Posts: 77
I took this example from the study guide titled "java 6 and j2ee 1.5 Black Book"



The book states that since the method signatures are identical, the compiler fails to bind the methods to their definitions, and it is done at run time. But the problem is that these methods are declared static. To the best of my knowledge static methods are bound at compile time. Which one is right?
Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 203

I think static methods are not overridden ..!!
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3895
    
  18

Oceana, have you tried running the code?


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Oceana Wickramasinghe
Ranch Hand

Joined: Mar 02, 2011
Posts: 77
Yes the output is

Square of the given value: 25.0
Area of the rectangle: 30.0

Tried with nulls, no difference.

I dont know how a study guide could make such a huge error.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20049
    
  30

Saral is right. Fields and static members cannot be overridden, only shadowed. The reference type determines which one is called, not the actual type.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Saral Saxena
Ranch Hand

Joined: Apr 22, 2011
Posts: 203

Rob Spoor wrote:Saral is right. Fields and static members cannot be overridden, only shadowed. The reference type determines which one is called, not the actual type.


Hi Rob,

Yeah agreed ..!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static binding question
 
It's not a secret anymore!