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.

1

There are 1 best solutions below

0
ndc85430 On

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.