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();
}}
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();
}}
举一反三
- 有如下类的定义[br][/br] public class Point { int x;[br][/br] int y;[br][/br] public void show(){ System.out.println("x="+x+",y="+y)[br][/br] }[br][/br] public Point(){[br][/br] }[br][/br] public Point(int x , int y){ this.x = x;[br][/br] this.y = y;[br][/br] }[br][/br] } Point p1 = new Point(); Point p2 = new Point(); Point p3 = new Point(1,1); 关于创建的对象说法不正确的是() A: p1==p2的值是true B: p1.show()的输出结果是x=0,y=0 C: p3.show()输出的结果是x=1,y=1 D: p1.x = 10,是将p1对象的x属性赋值为10,不能改变p2和p3对象的x属性值。
- 下列程序的运行结果? public class Test { public static void main(String a[]) { int x=3,y=4,z=5; if (x>3) { if (y<2) System.out.println("show one"); else System.out.println("show two"); } else { if (z>4) System.out.println("show three"); else System.out.println("show four"); } } }
- 下面定义结构体数组的代码段正确的是()。 A: struct POINT{ public double x;//横坐标 public double y;//纵坐标}POINT[] p;p=new POINT[100]; B: struct POINT{ public double x;//横坐标 public double y;//纵坐标}POINT p[100]; C: struct POINT{ public double x;//横坐标 public double y;//纵坐标}POINT p[]=new POINT[100]; D: struct POINT{ public double x;//横坐标 public double y;//纵坐标}POINT p=new POINT[100];
- 设(X,Y)的联合分布律如下表所示,则以下结果错误的是 [img=385x148]1802d3f4c0617e4.jpg[/img] A: P(Y=1|X=1)=P(Y=1|X=2) B: P(Y<1)<P(Y>1) C: P(Y≤1)<P(Y≥1) D: P(X=2)=1.5P(X=1) E: P(Y=0)=P(Y=1) F: P(X=1︱Y=1)=P(X=2|Y=1) G: P(X=1︱Y=0)<P(X=2|Y=0) H: P(X=1︱Y=2)+P(X=2|Y=2)=1 I: P(Y≥0)=1
- 有以下程序: #include <iostream> #include <cmath> using namespace std; class Distance; class point { public: friend class Distance; Point(int a,int B) { x=a; Y=b; } void Print() { cout<<"X= "<<X<<end1; cout<<"Y= "<<Y<<end1; } private: float X,Y; }; class Distance { public: float Dis(Point &p,Point &q); }; float Distance :: Dis(Point &p,Point &q) { float result; result=sqrt((p.X-q.X)*(p.X-q.X)+(p.Y-q.Y)*(p.Y-q.Y)); cout<<result<<end1; retUrn result; } int main() { Point p(10,10),q(10,30); Distance d; d.Dis(p,q); return 0; } 运行后的输出结果是( )。 A: 10 B: 30 C: 0 D: 20