Global variables in Java

后端 未结 24 2218
青春惊慌失措
青春惊慌失措 2020-11-22 11:56

How do you define Global variables in Java ?

24条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 12:24

    You don't. That's by design. You shouldn't do it even if you could.

    That being said you could create a set of public static members in a class named Globals.

    public class Globals {
       public static int globalInt = 0;
       ///
    }
    

    but you really shouldn't :). Seriously .. don't do it.

提交回复
热议问题