How would I use a variable declared within an if statement in another method of the same class??
Ex.
public static void declaration_st(ArrayList E) {
if (look("float")) {
String funcID = tokM1(E).getToken(); //I Want to use this funcID in another method
Juccept("float");
} else if (look("int")) {
String funcID = tokM1(E).getToken(); //or if the program gets to an int I want it to use this funcID from this if statement in another method
}
}
If you want to use that variable inside a different method, then you probably should think of making that variable as a field of the class.
class Cls {
private String funcID;
public static void declaration_st(ArrayList E) {
if (look("float")) {
funcID = tokM1(E).getToken(); // now you can access funID from any method.
Juccept("float");
} else if (look("int")) {
funcID = tokM1(E).getToken();
}
}
}
How would I use a variable declared within an if statement in another method of the...