首页 > 试题广场 >

请说出A类中System.out.println的输出结果。

[问答题]
请说出A类中System.out.println的输出结果。
class B{
    int x = 100,y=200;
    public void setX(int x){
        x=x;
    }
    public void setY(int y){
        this.y=y;
    }
    public int getXYSum(){
        return x+y;
    }
}
public class A {
    public static void main(String args[ ]){
        B b =new B();
        b.setX(-100);
        b.setY(-200);
        System.out.println("sum="+b.getXYSum());
    }
}

因为有this.y=y
所以最终结果为-100
发表于 2022-09-19 19:46:56 回复(0)
-100
发表于 2020-07-19 16:17:36 回复(0)
-100
发表于 2020-03-15 17:28:56 回复(1)