• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Overriding static methods?  RSS feed

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I read some where that we can't override the static methods.
But this program works fine.
Can any one explain abt static methods override?



( tags added)
[ February 25, 2005: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramana,

A subclass cannot override methods that are declared static in the superclass. A subclass can hide a static method in the superclass by declaring a static method in the subclass with the same signature as the static method in the superclass.
[ February 25, 2005: Message edited by: Srinivasa Raghavan ]
 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramanna,
By the code what u have written u may not be able to conclude that ur static methods are overridden or not.
Try this way:


After running,
U can see that the method being called is not of Object check1, but of check2
But if the methods are not static,u get a different behaviour

Hope u understand.
 
Ramana Uppala
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
I got the point.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!