Can I override and overload static methods in Java? -


i'd know:

  1. why can't static methods overridden in java?
  2. can static methods overloaded in java?

static methods can not overridden in exact sense of word, can hide parent static methods

in practice means que compiler decide method execute @ compile time, , not in runtime, overridden instance methods.

for neat example have here.

and this java documentation explaining difference between overriding instance methods , hiding class (static) methods.

overriding: overriding in java means particular method called based on run time type of object , not on compile time type of (which case overriden static methods)

hiding: parent class methods static not part of child class (although accessible), there no question of overriding it. if add static method in subclass, identical 1 in parent class, subclass static method unique , distinct static method in parent class.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -