Skip to main content
8 of 8
grammar
Frank Hileman
  • 3.9k
  • 17
  • 18

What are the differences between class variables and instance variables in Java?

I'm very new to Java and want to understand the difference between class variables and instance variables.

For example:

class Bicycle { 
    static int cadence = 0; 
    int speed = 0; 
    int gear = 1; 
}

How are instance variables and class variables different from each other? Which variables here are class variables, and which are instance variables? How does this affect scope?

Skylar Adams
  • 433
  • 2
  • 4
  • 6