When I learn Java Programming online, I have message “Variable Name” Cannot be Resolved to a Variable. I checked my code with my teacher code. It is exactly the same. But I have this error message.
But I try to finish the code, and the error message is disappear by itself… :)
The code is consisted of 2 classes: objectIntro and objectIntroTest. The problem code is in the waterAmount variable. But I keep finish the program, and the error message is disappeared.
package tes2;
public class objectIntro {
int tWater = 0;
public objectIntro() {
}
public objectIntro(int waterAmount) {
tWater = waterAmount;
}
public void addWater(int amount) {
tWater = tWater + amount ;
}
public void drinkWater(int amount) {
tWater = tWater - amount;
}
public int getWater() {
return tWater;
}
}
Ini adalah Class yang kedua untuk mentesnya:
package tes2;
public class objectIntroTest {
public static void main(String[] args) {
String x = "Hello";
objectIntro waterBottle = new objectIntro(0);
waterBottle.addWater(100);
waterBottle.drinkWater(20);
System.out.println("The remaining of water is " + waterBottle.getWater()) ;
}
}
Program
Filed under: Agus Nizami, Java Programming Language | Tagged: Cannot be Resolved to a Variable, Java, Java Programming |
Tinggalkan Balasan