Lu Yas
Lu Yas

Reputation: 137

Global variables in C++ to Java

How can i write all these global variables of C++ in Java?

  //Global variables
  int charClass;
  char lexeme [100];
  char nextChar;
  int lexLen;
  int token;
  int nextToken;
  extern string word("Apple");

Upvotes: 0

Views: 160

Answers (1)

MByD
MByD

Reputation: 137282

How about public static variables in a class?

public class Globals {
    public static int charClass;
    public static char[] lexeme = new char[100];
    public static char nextChar;
    public static int lexLen;
    public static int token;
    public static int nextToken;
    public static String word = "Apple";
}

There are several differences but the main idea is similar (as least for the primitives).

Upvotes: 6

Related Questions