如果你要直接用a这个变量的话要把它用static修饰,然后可以用set方法给他赋值,或者不用static,因为你设置的是私有变量,想要获取a的值就要新建一个对象,然后调用get方法得到a的值
public class example {
private int a;
private int b;
public void setA(int a) {
this.a = a;
}
public void setB(int b) {
this.b = b;
}
public int getA() {
return a;
}
public int getB() {
return b;
}
public static void main(String[] args){
example e=new example();
e.setA(10);
e.setB(55);
System.out.println("a="+e.getA()+" b="+e.getB())
}
}