Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

All about static methods

 
Anuj Singh
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why cant we override static methods?
 
Samrat Som
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey this link will help you better to understand than my explanation
webpage
 
Antany Vasanth
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
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
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.
 
Amandeep Singh
Ranch Hand
Posts: 850
  • 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!!
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic