import java.util.Scanner;
public class Test
{
public static void main(String args[])
{
new Test();
}
private int numofCaves= 0;
public Test() {
System.out.println(getNumofCaves()); // prints 0
setNumofCaves(10);
System.out.println(getNumofCaves()); //prints 10
}
public int getNumofCaves() {
return numofCaves; // The return value is 0
}
public void setNumofCaves(int numofCaves) {
this.numofCaves = numofCaves;// The return value is 10
}
}
Worked perfectly fine for me. You are probably referring to these methods with 2 different objects that have different values for numOfCaves.

New Topic/Question
Reply




MultiQuote



|