• 2021-04-14
    8.5 阅读程序,写出运行结果
    class Point{
    int x=1;
    static int y=2;
    public void show(){System.out.println(x+","+y); }}
    public class tempDemo{
    public static void main(String []args){
    Point p1=new Point();p1.show();
    p1.x=2;p1.y=3;
    Point p2=new Point();p2.show();
    p1.show();
    p1.y=5; p2.show();
    }}

  • 1,2 --- 1,3 --- 2,3 --- 1,5

    举一反三

    内容

    • 0

      class Person {private int a;public int change(int m){ return m; }}public class Teacher extends Person {public int b;public static void main(String arg[]){Person p = new Person();Teacher t = new Teacher();int i;// point x}}在 // point x安排哪个语句合法?

    • 1

      请说出E类中[代码1]和[代码2]的输出结果。 class A{ double f(int x, double y){ return x+y; } int f(int x,int y) { return x*y; } } public class E{ public static void main(String args[ ] ){ A a=new A(); System.out.println(a.f(10,10)) ; // [代码1] System.out.println(a.f (10,10.0)) ; // [代码2] } }

    • 2

      以下代码的输出结果为( ) public class Pass{ static int j = 20; public void amethod(int x){ x = x*2; j = j*2; } public static void main(String args[]){ int i = 10; Pass p = new Pass(); p.amethod(i); System.out.println(i+" and "+j); } }

    • 3

      【填空题】设两个随机变量X与Y独立同分布,且P(X=-1)=P(Y=-1)=1/2,P(X=1)=P(Y=1)=1/2,则P(X=Y)=____、P(X+Y=0)=____、 P(XY=1)=____.

    • 4

      设随机变量X和Y相互独立同分布,已知P{X=1}=P{Y=1}=1/3,P{X=2}=P{Y=2}=2/3,则有( ).