How to call a variable in another method?

前端 未结 4 1031
暖寄归人
暖寄归人 2021-01-17 00:04

How to call a variable in another method in the same class?

public void example(){    
    String x=\'name\';
}

public void take()         


        
4条回答
  •  广开言路
    2021-01-17 00:41

    public class Test
    {
    
    static String x;
    public static void method1
    {
    x="name";
    }
    
    public static void method2
    {
    
    System.out.println(+x);
    
    }
    
    }
    

提交回复
热议问题