我有这个班级
public class A {
private int number; //A number instance
public A() { //At the beginning number is 0
number=0;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public void Str(String v) { //for given string number is gonna string's length
setNumber(v.length());
}
}
我有这个B级
public class B {
public static void main(String[] args) {
A a1=new A();//A class instance
a1.Str("hello");//giving hello string
System.out.println(a1.getNumber()); //this one is 0
}
}
当我运行此示例代码时,a1.getNumber为0.这里可能有什么问题?