Skip to content

Q 17 - Overriding Static Method & Static Variables #21

Discussion options

You must be logged in to vote

Great question! Let’s unravel the mystery of static variables and methods in Java—stylishly. 🌟


🚫 Can Static Variables or Methods Be Overridden?

❌ Static Variables — Cannot Be Overridden

  • Why? Static variables belong to the class, not to instances. Since overriding is a behavior related to instances and inheritance, static variables don’t play that game.
  • Think of them as global settings shared across all objects of the class.

❌ Static Methods — Cannot Be Truly Overridden

  • Static methods are bound during compile-time, not runtime—so they follow method hiding, not overriding.
  • If a subclass defines a static method with the same signature as one in its superclass:
    • The superclass method is h…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by AmjustGettingStarted
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants