• Post Reply Bookmark Topic Watch Topic
  • New Topic

All about static methods  RSS feed

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why cant we override static methods?
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey this link will help you better to understand than my explanation
webpage
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anuj,

Static methods or variables are class level not instance level.

You can directly access static methods without creating object for that class.

Static methods can't be overridden but can be re-defined in its subclass.

Consider the following example



Hope you understand it.

Regards,
Antany
 
Sheriff
Posts: 21289
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read http://faq.javaranch.com/java/OverridingVsHiding as well.
 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
very nice explanation.
 
Anuj Singh
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Antany,
A lovely explanation!Thanks a ton!!
 
Marshal
Posts: 58424
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Samrat Som wrote:hey this link will help you better to understand than my explanation
webpage

But that link uses C# rather than Java, so only the Strategy Pattern solution will work for us.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!