Skip to main content
4 of 8
http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts
gnat
  • 20.8k
  • 29
  • 115
  • 295

what's the difference between class variables and instance variables in java?

I'm very new to java and I'm trying my best to understand it. One of the brick walls i've hit is the difference between class and instance variables.

For example:

class Bicycle { 

    int cadence = 0; 
    int speed = 0; 
    int gear = 1; 

So is this a class or instance variable and how are the two different from each other.

I'm also having trouble understanding how several instance variables can be different from each other and yet come from the same class variable.

Skylar Adams
  • 433
  • 2
  • 4
  • 6