-2

In Java we can use

  • non-static variables inside non-static methods without creating an instance within the same class.

  • static variables inside non-static methods without having an issue within the same class.

  • static variables inside a static a static method without having any issue within the same class.

I just want to know why we can not use a non static variable inside a static method within the same class.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

-1

It wouldn't make sense. Static methods are about belonging to the class, rather than individual instances. So, they don't have access to any instance (i.e. you can't use this™ inside them).

Things that aren't static are bound to individual instances.

ndc85430
  • 1,395
  • 3
  • 11
  • 17