Read class variables in different files


Joined
May 15, 2022
Messages
1
Reaction score
0
"Java language" - Help please
I have a class called "Personaje" where I have the variables
int vida = 5;
int randomNumber;
I have another class called "Mago" and I add a Personaje extends to it so that it reads the Personaje variables
At the moment of creating my function, it only reads me the variable of "numberRandom" and if the random number falls in 0,1,2 it sends a print of doing nothing and it works fine, but if it falls 3,4,5 to the variable Personaje vida has to be subtracted by 1, only when it drops to 345, the else if enters fine but it does not subtract in vida. and I want to know how I do it so that if I subtract :l

Personaje Class


Mago class


I run the program, it recognizes the variable numeroRandom the number 4 falls but it does not subtract from life


Recognizes the variable number Random and returns to 2
 
Ad

Advertisements

Joined
Mar 28, 2022
Messages
48
Reaction score
6
In an instance of a class, variables are usually referred to like so
Java:
this.vida = this.vida - 1;
Maybe this is the problem?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top