Can static method access non-static instance variable?

后端 未结 5 2231
天命终不由人
天命终不由人 2020-12-16 19:31

So my understanding was that you can\'t use static method to access non-static variables, but I came across following code.

class Laptop {
  String memory =          


        
5条回答
  •  遥遥无期
    2020-12-16 19:47

    try this code

    public static void repair() {
    
        Laptop laptop =new Laptop();
    
        laptop.memory="2GB";
    
      }
    

提交回复
热议问题