Answer the question
In order to leave comments, you need to log in
How to fix error: cannot find symbol?
Learning Java, Compiling Code
public class Evolution {
public static void main(String[] args) {
Amoeba a1 = new Amoeba(5);
a1.setChromosomes(5);
a1.infoAmoeba();
}
}
class Amoeba {
static int Amount;
static boolean established = false;
public Amoeba(int n) {
if (established) {
Amount += 1;
} else {
Amount = n;
}
int num = Amount;
established = true;
}
private int Chromosomes;
public void setChromosomes(int x) {
Chromosomes = x;
}
public void infoAmoeba() {
System.out.println("Amoeba №: " + num + ":");
if (Chromosomes == 0) {
System.out.println("Chromosomes: unknown " + "; " + "Amount: " + Amount + ";");
} else {
System.out.println("Chromosomes: " + Chromosomes + "; " + "Amount: " + Amount + ";");
}
}
}
Evolution.java:28: error: cannot find symbol
System.out.println("Amoeba тДЦ: " + num + ":");
^
symbol: variable num
location: class Amoeba
1 error
Answer the question
In order to leave comments, you need to log in
Good afternoon
In the same place it is written in black and white that it cannot find the symbol num
System.out.println("Amoeba №: " + num + ":");
. The variable you have declared inside the public class and is not available in the method itself.
int num = Amount;
Read about variable scope
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question