Class Variables VS Instance Variables

What are instance and Class Variables?

A class variable is a variable defined in a class body that can be interacted with without an instance of such class. Class variables are shared among all instances of the class and its subclasses.

Class Variables

Let's explore how class variables behave in Java with the following example.

Instance Variable

Let’s explore the behavior of instance variables this time.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gary Cordero Rosa

Gary Cordero Rosa

Flatiron School Software Engineering Student