-4

Please tell me the difference between a global variable and an instance variable. I am a little bit confused about it. Also, what is a user-defined variable?

khelwood
  • 55,782
  • 14
  • 81
  • 108
rahil
  • 29
  • 6
  • 1
    [FYI](http://java-latte.blogspot.in/2014/01/global-variable-vs-class-variable-vs.html) – Bhargav Modi Mar 13 '15 at 10:03
  • The closest thing to a 'global variable' in Java is implemented with a public constant in some (public) class or interface, as explained in http://stackoverflow.com/questions/4646577/global-variables-in-java. An instance variable is a field at the class level. – Oscar Mar 13 '15 at 10:04

1 Answers1

0

Instance variables are non static variables declared in a class, but outside a method, constructor or any block.

Class(similar to global, as there is no term as global in java) variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block.

Community
  • 1
  • 1
codingenious
  • 8,385
  • 12
  • 60
  • 90