Anubody可以解释如何使用set方法吗?问题:
class Sonum {
private int prior;
public Sonum(int prior) {
this.prior = prior;
}
public int getPrior() {
return prior;
}
public void setPrior(int prior) {
this.prior = prior;
}
class Tel {
// Please explain how can I set the value for prior? (for example 2)
}
最佳答案
好吧,首先,您需要一个Sonum
实例,您要在该实例上设置prior
值。例如:
class Test {
public void foo() {
Sonum sonum = new Sonum(5);
// Use it with a prior of 5
// ...
sonum.setPrior(10);
// Now use it with a prior of 10
}
}
关于java - 在Java中设置方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5567115/