Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static methods - final

 
Arnb Sen
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I read that


static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object.


I cannot make a sense of this. I want to try some code which explains this. Any help ?

* implicitly final ?
* overriding is done based on the type of the object ?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it's not true. Static methods aren't implicitly final. Where did you read this? I suggest you simply disregard this statement, as it will just lead to confusion.

It's possible (mmmm, probable) that the author was trying to say that static methods can't be overridden. This is true, but it's not the same as being final. See here for more about "overriding" static methods if you want to learn more.
 
Arnb Sen
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jim. I will ignore that statement.

How about the next one ? "overriding is done based on the type of the object ?" - what does this mean ? If this is not correct either - I better give up the article that I am reading on the net
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think "attached to the object" means that different objects are formed from different classes, and object A might be from a subclass of the class object B is from, so the two objects have different methods.
I think your suggestion of reading something else might be a good one
CR
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic