Can a static method access non static property in java? The simple answer is “No”. But there is an indirect method to do this. Consider the following code:
- The line 12 creates an object. We can not access non static property without having the instance of a class.
- The line 14 passes the object to a static method. The static method will change the non-static variable i which actually belongs to an object.
Like us on facebook fb.com/JavaWithUmer