若有类Z说明class Z{staticint a;public:static void fStatic(Z&);};int Z::a=0;Z objZ;,则函数fStatic中访问数据a错误的是()。A、void Z::fStatic(){obj Z.a=1;}B、void Z::fStatic(){a=1;}C、void Z::fStatic(){this->a=0;}D、void Z::fStatic(){Z::a=0;}

题目

若有类Z说明class Z{staticint a;public:static void fStatic(Z&);};int Z::a=0;Z objZ;,则函数fStatic中访问数据a错误的是()。

  • A、void Z::fStatic(){obj Z.a=1;}
  • B、void Z::fStatic(){a=1;}
  • C、void Z::fStatic(){this->a=0;}
  • D、void Z::fStatic(){Z::a=0;}

相似考题
更多“若有类Z说明class Z{staticint a;public:static void fStatic(Z);};int Z::a=0;Z objZ;,则函数fStatic中访问数据a错误的是()。A、void Z::fStatic(){obj Z.a=1;}B、void Z::fStatic(){a=1;}C、void Z::fStatic(){this-a=0;}D、void Z::fStatic(){Z::a=0;}”相关问题
  • 第1题:

    执行下列代码段之后,变量z的值为______。 Public class Test8 { public static void main(String[] args) { int x=2; int y=3; int z=4; z-....= y-x--; System.out.println(z); }

    A.1

    B.2

    C.3

    D.4


    正确答案:D
    解析:表达式中的运算次序应该是先对y做减量运算,得到y=2,然后再取x的值x=2,做减法运算得到0,最后用z减去0,得到答案为4。

  • 第2题:

    以下程序输出结果是 ______。includevoid fun(int x,int y,int z){z=x+y;}void main

    以下程序输出结果是 ______。 #include<iostream.h> void fun(int x,int y,int z){z=x+y;} void main() { int a=10; fun (2,2,a); cout<<a; }

    A.0

    B.4

    C.10

    D.无定值


    正确答案:C

  • 第3题:

    若有以下程序: #include 〈iostream〉 using namespace std; class A { private: int x; public: int z; void setx(int i) { x=i; } int getx () { return x; } }; class B : public A { private: int m; public: int p; void setvalue(int a,int b, int C) { setx (A) ; z=b; m=c; } void display() { cout〈〈getx()〈〈","〈〈z〈〈","〈〈m〈〈end1; } }; int main ( ) { B obj; obj.setvalue(2,3,4); obj.display(); return 0; } 程序运行以后的输出结果是( )。

    A.产生语法错误

    B.2,3,4

    C.2,2,2

    D.4,3,2


    正确答案:B
    解析:本题考核公有继承中的类成员访问权限。当类的继承方式为公有继承时,基类的公有成员和保护成员分别作为派生类的公有成员和保护成员,派生类的其他成员可以直接访问它们。其他外部使用者只能通过派生类的对象访问继承来的公有成员。在本题中,数据成员z和函数setx()都是基类A的公有成员,它们经过公有继承以后,在派生类B中还是公有成员,而派生类B中的函数setValue()和display()都是公有成员,可以通过对象对它们进行访问。所以程序中对各成员的访问是正确的。本程序的功能是输出已设置的各成员的值。

  • 第4题:

    若有以下程序:includeusing namespace std;class A{private:int x;public:int z;void

    若有以下程序:#include<iostream>using namespace std;class A {private: int x;public: int z; void setx(int i) { x=i; } int getx () { return x; }}:class B : public A{private: int m;public: int p; void setvalue(int a, int b, int c) { setx(a) ; z=b; m=c; } void display{) { cout<<getx ()<<", "<<z<<", "<<m<<end1; }};int main(){ B obj; obj. setvalue(2,3,4); obj.display(); return 0;} 程序运行以后的输出结果是

    A.产生语法错误

    B.2,3,4

    C.2,2,2

    D.4,3,2


    正确答案:B
    解析:本题考核继承与派生。当类的继承方式为公有继承时,基类的公有成员和保护成员分别作为派生类的公有成员和保护成员,派生类的其他成员可以直接访问它们。其他外部使用者只能通过派生类的对象访问继承来的公有成员。在本题中,数据成员z和函数setx都是基类A的公有成员,它们经过公有继承以后,在派生类B中还是公有成员,而派生类B中的函数setvalue和display都是公有成员,可以通过对象对它们进行访问。所以程序中对各成员的访问是正确的。本程序的功能是输出已设置的各成员的值。

  • 第5题:

    阅读以下C++代码,填充(1)~(5)的空缺,将解答填入答题纸的对应栏内。 【说明】在下面程序横线处填上适当的字句,使其输出结果为:x=5x=6y=7x=8z=9【程序】#include<iostream.h>class X1{int x;(1):X1(int xx=0){x=xx;}(2)void Output()(cout<<"x="<<x<<end;}};(3)Y1:public X1{int y;public:Y1(int xx=0,int yy=0):X1(xx){y=yy;}(2)void Output(){(4)Output();cout<<"y="<<y<<end1;}};class Z1:pubtic X1{int z:(5):Z1(int xx=0,int zz=0):X1(xx){z=zz;}②void Output(){X1::Output();cout<<"z="<<z<<end1;}};void main(){X1 a(5);Y1 b(6,7);Z1 c(8,9);X1*p[3]={&a,&b,&c};For(int i=0;i<3;i++){p[i]-->Output();cout<<end1;}}


    答案:
    解析:
    (1)public
    (2)virtual
    (3)class
    (4)X1::
    (5)public
    【解析】

    通过对比三个类的定义就可以发现,在类X1和Z1的定义中缺少类的成员属性声明,而类一般将成员变量声明为公有的、私有的或受保护的三种类型中的一种,在类的定义中,我们一般将类的构造函数放在公有的属性下面,在题目中只能选择公有的属性了,因此,第1空和第5空中应该填“public”。对三个类的定义进行仔细观察后,我们同样可以发现,每个类中都定义了一个同名函数Output(),而且在后两个类的函数体中调用了函数Output(),由此,我们应该想到虚函数。虚函数的作用是允许在派生类中重新定义与基类同名的函数,并且可以通过基类指针或引用来访问基类和派生类中的同名函数。因此,第2空应该填“virtual”。第3空就简单了,考查类的定义,应该填类的标识符“class”。从程序中我们可以看到,类Y1和Z1都以公有的方式继承类X1。从输出的结果来分析,类Y1和Z1都输出了两个数,但单从类Z1的函数来看,只能输出一个变量的值z,因此,可以发现在类Z1中应该和类Y1一样,都调用了类X1的函数Output(),因此,第4空的答案为“X1::”。

  • 第6题:

    In which two cases does the compiler supply a default constructor for class A?()  

    • A、 class A{}
    • B、 class A { public A(){} }
    • C、 class A { public A(int x){} }
    • D、 class Z {} class A extends Z { void A(){} }

    正确答案:A,D

  • 第7题:

    现有:  class  Test4  {  public static void main (String  []  args)  {    boolean X=true;   boolean y=false;    short Z=42;    if((z++==42)  &&  (y=true))z++;    if((x=false)  ||    (++z==45))  z++;    System. out.println(¨z=”+z);     }    }  结果为:() 

    • A、  Z=42
    • B、  z=44
    • C、  Z= 45
    • D、  z= 46

    正确答案:D

  • 第8题:

    现有:  class Foo  {  public static void main (String  []  args)  {      int x=O;      int y=4;  for (int  z=0;  z<3;  Z++;  X++)  {     if(x>1&++y<10)    y++;    }  System. out .println (y);  }   }  结果是什么?()     

    • A、7
    • B、8
    • C、10
    • D、12

    正确答案:B

  • 第9题:

    abstract class A {  abstract void al();  void a2() { }  }  class B extends A {  void a1() { }  void a2() { }  }  class C extends B { void c1() { } }  and:  A x = new B(); C y = new C(); A z = new C();  Which four are valid examples of polymorphic method calls?()

    • A、 x.a2();
    • B、 z.a2();
    • C、 z.c1();
    • D、 z.a1();
    • E、 y.c1();
    • F、 x.a1();

    正确答案:A,B,D,F

  • 第10题:

    class Test4 {   public static void main(String [] args) {   boolean x = true;   boolean y = false;   short z = 42;   if((z++ = = 42) && (y = true)) z++;   if((x = false) || (++z = = 45)) z++;   System.out.println("z = " + z);   }   }   结果为:()  

    • A、z = 42
    • B、z = 44
    • C、z = 45
    • D、z = 46

    正确答案:D

  • 第11题:

    单选题
    若有类Z说明class Z{staticint a;public:static void fStatic(Z&);};int Z::a=0;Z objZ;,则函数fStatic中访问数据a错误的是()。
    A

    void Z::fStatic(){obj Z.a=1;}

    B

    void Z::fStatic(){a=1;}

    C

    void Z::fStatic(){this->a=0;}

    D

    void Z::fStatic(){Z::a=0;}


    正确答案: D
    解析: 暂无解析

  • 第12题:

    多选题
    public class MethodOver {  private int x, y;  private float z;  public void setVar(int a, int b, float c){  x = a;  y = b;  z = c;  }  }   Which two overload the setVar method?()
    A

    void setVar (int a, int b, float c){ x = a; y = b; z = c; }

    B

    public void setVar(int a, float c, int b) { setVar(a, b, c); }

    C

    public void setVar(int a, float c, int b) { this(a, b, c); }

    D

    public void setVar(int a, float b){ x = a; z = b; }

    E

    public void setVar(int ax, int by, float cz) { x = ax; y = by; z = cz; }


    正确答案: A,B
    解析: 暂无解析

  • 第13题:

    若有以下程序:include using namespace std;class A{private:int x;public:int z;voi

    若有以下程序:#include <iostream>using namespace std;class A{private: int x;public: int z; void setx(int i) { x=i; } int getx() { return x; }};class B: public A{private: int m;public: int p; void setvalue(int a, int b, int c) { setx(a); z=b; m=c; } void display() { cout<<getx()<<","<<z<<","<<m<<end1; }};int main(){ B obj; obj.setvalue(2,3,4); obj.display(); return 0;程序运行以后的输出结果是( )

    A.产生语法错误

    B.2,3,4

    C.2,2,2

    D.4,3,2


    正确答案:B

  • 第14题:

    若有以下程序:include using namespace std;class A{private: int x;protected: int

    若有以下程序: #include <iostream> using namespace std; class A { private: int x; protected: int y; public: int z; void setx(int i) { x=i; } int getx () { return x; }; class B : protected A { public: void setvalue(int a, int b, int c) { setx (a); y=b; z=c; } void display() { cout<<getx ( ) <<", "<<y<<", "<<z<<", "<<end1; } }; int main () { B obj; obj.setvalue(5, 6, 7); obj.display ( ); return 0; } 程序运行后的输出结果是( )。

    A.产生语法错误

    B.7,6,5

    C.5,6,7

    D.7,5,6


    正确答案:C
    解析:本题考核保护继承中对类成员的访问权限。①在保护继承中,基类公有成员和保护成员都以保护成员身份出现在派生类中,而基类私有成员不可访问。②基类的公有成员和保护成员被继承以后作为派生类的保护成员,这样,派生类的其他成员可以直接访问它们。③由保护派.生的类声明的对象,不能访问任何基类的成员。在本题中,基类A中的数据成员y和函数setx,经过保护继承以后,在派生类B中成为保护成员,派生类B的对象不能访问它们。而派生类B中的函数setvalue和display都是公有成员,可以通过对象对它们进行访问。所以程序中对各成员的访问是正确的。本程序的功能是对类中各数据成员进行赋值,然后查看赋值是否正确。

  • 第15题:

    以下程序执行后的输出结果是includeusing namcspace std;void try(int,int,int,int);

    以下程序执行后的输出结果是 #include<iostream> using namcspace std; void try(int,int,int,int); int main() { int x,y,z,r; x=1; y=2; try(x,y,z,r); cout<<r<<end1; return 0; } void try(int x,int y, int z,int r) { z = x+y; x = x*x; y = y*y; r = z+x+y; }

    A.18

    B.9

    C.10

    D.不确定


    正确答案:D
    解析:本题考核函数调用(参数的传递)。本题常见的错误解答是:把x=1,y=2代入到函数try中,逐步计算出r=8。最后得到r的输出值是8。以下是正确解答,根据程序逐步分析:程序中定义了一个名为try的void型函数,即函数try没有任何返回值。而try函数在main函数中是以一条独立语句的方式被调用的,且main函数最后输出变量r的值。但在main函数中,并没有对变量r赋值。在C++语言中,数据只能从实参单向传递给形参,称为按值传递。也就是说,当简单变量作为实参时,用户不能在函数中改变对应实参的值。所以虽然在函数try中,r的值为8,但它并不能传递给实参,当然最终的输出肯定是不确定的随机数了。

  • 第16题:

    以下程序的输出结果为:public class test {public static void main(String args[]) {int x=1,y=1,z=1;if (x--==1&&y++==1||z++== 1、System.out.println("x="+x+",y="+y+",z="+z);}}

    A. x=0,y=2,z=1

    B. x=1,y=2,z=1

    C. x=0,y=1,z=1

    D. x=0,y=2,z=2


    正确答案:A

  • 第17题:

    给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载。public class Test {  public void cal(int x, int y, int z) { } //A } 

    • A、public int cal(int x,int y,float z){return 0;}
    • B、public int cal(int x,int y,int z){return 0;}
    • C、public void cal(int x,int z){}
    • D、public viod cal(int z,int y,int x){}

    正确答案:A,C

  • 第18题:

    现有:  class Test2  f  public static void main (String  []  args)  {      boolean X= true;      boolean y=false;      short Z=20;      if((x==true)  &&  (y=true))  z++;     if((y==true) ||  (++z==22))  z++;      System. out .println( "z="+z);      }      结果是什么?()     

    • A、Z=21
    • B、Z=22
    • C、Z=23
    • D、Z= 24

    正确答案:B

  • 第19题:

    class Foo {  public static void main(String [] args) {  int x = 0;  int y = 4;  for(int z=0; z 〈 3; z++, x++) {  if(x 〉 1 & ++y 〈 10) y++;  }  System.out.println(y);  }  }  结果是什么?()  

    • A、6
    • B、7
    • C、8
    • D、10

    正确答案:C

  • 第20题:

    public class MethodOver {   private int x, y;   private float z;   public void setVar(int a, int b, float c){   x = a;   y = b;   z = c;   }   }   Which two overload the setVar method?()

    • A、 void setVar (int a, int b, float c){  x = a;  y = b;  z = c;  }
    • B、 public void setVar(int a, float c, int b) {  setVar(a, b, c);  }
    • C、 public void setVar(int a, float c, int b) {  this(a, b, c);  }
    • D、 public void setVar(int a, float b){  x = a;  z = b;  }
    • E、 public void setVar(int ax, int by, float cz) {  x = ax;  y = by;  z = cz;  }

    正确答案:B,D

  • 第21题:

    public class Yikes {  public static void go(Long n) {System.out.println(”Long “);}  public static void go(Short n) {System.out.println(”Short “);}  public static void go(int n) {System.out.println(”int “);}  public static void main(String [] args) {  short y= 6;  long z= 7;  go(y);  go(z);  }  }  What is the result?() 

    • A、 int Long
    • B、 Short Long
    • C、 Compilation fails.
    • D、 An exception is thrown at runtime.

    正确答案:A

  • 第22题:

    多选题
    给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载。public class Test {  public void cal(int x, int y, int z) { } //A }
    A

    public int cal(int x,int y,float z){return 0;}

    B

    public int cal(int x,int y,int z){return 0;}

    C

    public void cal(int x,int z){}

    D

    public viod cal(int z,int y,int x){}


    正确答案: B,D
    解析: 暂无解析

  • 第23题:

    单选题
    现有:  class Foo  {  public static void main (String  []  args)  {      int x=O;      int y=4;  for (int  z=0;  z1&++y<10)    y++;    }  System. out .println (y);  }   }  结果是什么?()
    A

    7

    B

    8

    C

    10

    D

    12


    正确答案: A
    解析: 暂无解析