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

Static binding question

 
Oceana Wickramasinghe
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 203
Eclipse IDE Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think static methods are not overridden ..!!
 
Stephan van Hulst
Bartender
Pie
Posts: 4840
34
Chrome Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oceana, have you tried running the code?
 
Oceana Wickramasinghe
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saral is right. Fields and static members cannot be overridden, only shadowed. The reference type determines which one is called, not the actual type.
 
Saral Saxena
Ranch Hand
Posts: 203
Eclipse IDE Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic