Skip to content

Q 29 - Static vs Instance #34

Discussion options

You must be logged in to vote

✅ Difference Between Static and Instance Variables in Java

Feature Static Variable Instance Variable
Definition Belongs to the class, shared by all objects Belongs to the object, unique for each instance
Memory Allocation Allocated once in memory (class area) Allocated each time an object is created
Accessed Using ClassName.variableName or via object Only via object reference
Scope Common to all objects of the class Specific to each object
Usage For constants, counters, configurations, etc. For storing object-specific state
Modifier Declared using the static keyword No static keyword needed
Lifetime Exists till the program ends Exists till the object is referenced

🧠…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by HARSHITH-MV
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