给出如下源代码,如何使成员变量m被方法fun()直接访问?() class Test { private int m; public static void fun() { //some code... } }A.将 private int m;改为 protected int m;B.将 private int m;改为 public int m;C.将 private int m;改为 static int m;D.将 private int m;改为 int m;

给出如下源代码,如何使成员变量m被方法fun()直接访问?() class Test { private int m; public static void fun() { //some code... } }

A.将 private int m;改为 protected int m;

B.将 private int m;改为 public int m;

C.将 private int m;改为 static int m;

D.将 private int m;改为 int m;


参考答案和解析
C

相关考题:

有如下类定义:class Test{public:Test(){ a = 0; c = 0;} // ①int f(int a)const{this-a = a;} // ②static int g(){return a;} // ③void h(intB . {Test::b = b;}; // ④private:int a;static int b;const int c;};int Test::b = 0;在标注号码的行中,能被正确编译的是A . ①B . ②C . ③D . ④

有如下程序:#includeusing namespace std;class Base{private:void funl() const{cout"funl";}protected:void fun2() const{cout"fun2";}public:void fun3() const{cout"fun3";}};class Derived:protected Base{public:void fun4() const{cout"fun4";}};int main(){Derived obj;obj.funl(); // ①obj.fun2(); // ②obj.fun3(); // ③obj.fun4(); // ④return 0;}其中有语法错误的语句是A . ①②③④B . ①②③C . ②③④D . ①④

下列程序段中包含4个函数,其中具有隐含this指针的是( )。 int funl(); class Test{ public: int fun2(); friend int fun3(); static int fun4(); };A.fun1B.fun2C.fun3D.fun4

已知如下类定义: class Base { public Base (){ //... } public Base ( int m ){ //... } protected void fun( int n ){ //... } } public class Child extends Base{ // member methods } 如下哪句可以正确地加入子类中?() A.private void fun( int n ){ //...}B.void fun ( int n ){ //... }C.protected void fun ( int n ) { //... }D.public void fun ( int n ) { //... }

已知如下类说明: public class Test { private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg[]) { Test t = new Test(); // 程序代码… } } 如下哪个使用是正确的?() A.t.fB.this.nC.Test.mD.Test.n

给出下列代码,如何使成员变量m被方法fun( )直接访问?Class Test{private int m;public static void fun( ){} }A.将private int m改为protected int mB.将private int m改为public int mC.将private int m改为static int mD.将private int m改为int m

包容类Contain和内嵌类Embed定义如下:include class Contain{private:int x;protec 包容类Contain和内嵌类Embed定义如下: #include <iostream.h> class Contain { private: int x; protected: int z; public: class Embed { private: int y; public: Embed(){y=100;} int Embed_Fun(); }MyEmbed; int Contain_Fun(); }; 对上面的定义,正确的描述是( )。A.定义类Embed对象的语句是:Contain::Embed embed;B.类Contain的成员函数Contain_Fun()中可以用MyEmbed.y的方式访问类Embed的私有成员yC.类Embed的成员函数Embed_Fun()中可以直接访问类Contain和的私有成员xD.类Embed的成员函数Embed_Fun()中可以直接访问类Contain的保护成员z

下列函数中,具有隐含的this指针的是( )。void fun1(); //①class MyClass{public:friend void fun2(); //②static int fun3(); //③int fun4(); //④}; A. ①B.②C.③D.④

给出下列代码,如何使成员变量m被方法fun( )直接访问? class Test{ private int m; public static void fun( ){ … } }A.将private int m改为protected int mB.将private int m改为public int mC.将private int m改为static iD.将private int m改为int m

已知有下列类的说明,则下列哪个语句是正确的?public class Test { private float f=1.0f; int m=12; static int n=1; public static void main(String arg[]) { Test t= new Test(); }}A.t.f;B.this. nC.Test.m;D.Test.f;

若有如下类定义: class B{ void fun1( ){} private: double varl; public: void fun2( ){ } }; class D:public B{ private: void fun3( ){ } }; 已知obj是类D的对象,下列语句中不违反类成员访问控制权限的是A.obj.fun1( );B.obj.varl;C.obj.fun2( );D.obj.fun3( );

有如下程序:include using namespace std;class Base{ public: void fun() { cout 有如下程序: #include <iostream> using namespace std; class Base { public: void fun() { cout<<"Base::fun"<<endl; } }; class Derived : public Base { public: void fun() { ______ cout<<"Derived::fun"<<endl; } }; int main() { Derived d; d.fun(); return 0; } 已知其执行后的输出结果为: Base::fun Derived::fun 则程序中下划线处应填入的语句是( )。A.Base.fun();B.Base::fun();C.Base->fun();D.fun();

包容类Contain和内嵌类Embed定义如下:includeclass Contain{private:int X;protect 包容类Contain和内嵌类Embed定义如下: #include<iostream.h> class Contain { private: int X; protected: int z; public: class Embed { private: int y; public: Embed(){y=100;} int Embed_Fun(); }MyEmbed; int Contain_Fun(A.定义类Embed对象的语句是:Contain? Embed embed;B.类Contain的成员函数Contain_Fun()中可以用MyEmbe D.y的方式访问类Embed的私有成员yC.类Embed的成员函数Embed_Fun()中可以直接访问Contain的私有成员xD.类Embed的成员函数Embed_Fun()中可以直接访问Contain的保护成员Z

已知有下面的类说明: public class Test4 { private float f=1.0f; int m=12; static int n=1; public static void main(String args[]) { Test4 e=new Test4(); } } 在main()方法中,下面哪个的使用是正确的? ( )A.e.fB.this.nC.Test4.mD.Test4.f

请在每条横线处填写一个语句,使程序的功能完整,且输出结果为91 1。注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。源程序文件代码清单如下:public class Outer{public static void main (String args[]{Outer i = new Outer();i,taskInner();}public class Inner{private int size;public void doSomething(int size){_____________//访问局部变量this. size++; //访问内部类的成员变量_____________//访问外部类的成员变量System.out.println(size+" "+this.size+" "+Outer.this.size);}}public void taskInner(){___________k.doSomething(8);}private static int size;}

有如下程序:include using namespace std;class Base{public:void fun() {cout 有如下程序:#include <iostream>using namespace std;class Base { public: void fun() {cout<<"Base:: fun"<<end1; }};class Derived: public Base ( public: void fun() { ____________________________ cout<<"Derived:: fun"<<end1; }};int main() { Derived d; D. fun(); return O;}已知其执行后的输出结果为:Base:: funDerived:: fun则程序中下划线处应填入的语句是( )。A.Base. fun ();B.Base:: fun ();C.Base->fun();D.fun()

使用VC6打开考生文件夹下的工程test12_1,此工程包含一个源程序文件test_12.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果如下:fun (Sample p) 1 2fun (Sample *p) 3 420 10源程序文件test12_1清单如下:include<iostream .h>class Sample{private:int x,y;static int z;public:Sample(int a,int b){ x=a;y=b; }void fun(Sample p);void fun(Sample *p);static void print(Sample s);};/*************** found ***************/int z=10;void Sample::fun(Sample p){x=p.K;y=p.y;cout<<"fun(Sample p)"<<" "<<x<<" "<<y<<endl;}void Sample::fun(Sample *p){/************** found **************/x=p.x; y=p.y;cout<<"fun(Sample *p) "<<" '<<x<<" "<<y<<endl;}void Sample::print (Sample s){/*************** found *****************/x=20;cout<<s. x<<" "<<z<<endl;}void main(){Sample p(1,2),q(3,4);p. fun(p);p. fun(q);p. print(p);}

将下面程序补充完整。 include using namespace std; class Base{ public: 【 】fun(){r 将下面程序补充完整。include <iostream>using namespace std;class Base{public:【 】 fun(){return 0;} //声明虚函数};class Derived:public Base{public:x,y;void SetVal(int a,int b){}int fun(){return x+y;}};void 【 】 SetVal(int a,int b){x=a;y=b;} //类Derived成员函数void main(){Derived d;cout<<d.fun()<<endl;}

写出程序的输出结果public abstract class A{public A(){Console.WriteLine('A');}public virtual void Fun(){Console.WriteLine("A.Fun()");}}public class B: A{public B(){Console.WriteLine('B');}public new void Fun(){Console.WriteLine("B.Fun()");}public static void Main(){A a = new B();a.Fun();}}

写出程序的输出结果:public class A{public virtual void Fun1(int i){Console.WriteLine(i);}public void Fun2(A a){a.Fun1(1);Fun1(5);}}public class B : A{public override void Fun1(int i){base.Fun1 (i + 1);}public static void Main(){B b = new B();A a = new A();a.Fun2(b);b.Fun2(a);}}

类 Contain 的定义如下: class Contain { private: int x; protected: int z; public: class Embed { private: int y; public: Embed ( ) { y=100; } int Embed_Fun(); }MyEmbed; int Contain_Fun(); }; 下列对上面定义的描述中,正确的是( )。A.定义类Embed对象的语句是:Contain::Embed Myobject;B.类Contain的成员函数Contain_Fun()中可以访问对象MyEmbed的私有成员yC.类Embed的成员函数Embed_Fun()中可以直接访问类Contain的所有成员D.类Embed的成员函数Embed_Fun()中只能直接访问类Contain的公有成员

有如下程序: include using namespace std; class Base { private: 有如下程序: #include<iostream> using namespace std; class Base { private: void funl()const {cout<<"funl";} protected: void fun2() const{cout<<"fun2";} public; void fun3() const {cout<<"fun3";} }; class Derived:protected Base { public; void fun4() const {cout<<"fun4";} }; int main() { Derived obj; obj.funl(); //① obj.fun2(); //② obj.fun3(); //③ obj.fun4(): //④ return 0; } 其中有语法错误的语句是A.①②③④B.①②③C.②③④D.①④

若有以下程序: #include 〈iostream〉 using namespace std; class sample { private: int i; public: void setvalue(int m) { i=m; } void fun(int m) { i+=m; } void disp() { cout〈〈i〈〈end1; } }; int main() { sample *ps; ps=new sample; ps-setvalue(20); ps-fun(5); ps-disp(); return 0; } 程序运行后,输出的结果是( )。A.15B.20C.25D.30

给出下面的程序代码如何使成员变量a被函数m()直接访问呢?()A.将private floata改为protected floataB.将private floata改为public floataC.将private floata改为static floataD.将private floata改为floata

有如下类定义: class B { public:void funl{} private:void fun2{} protected:void fun3{} }; class D:public B j protected:void fun4{} }; 若obj是类D的对象,则下列语句中不违反访问控制权限的是( )。A.obj.fun1;B.obj.fun2;C.obj.tim3;D.ohj.fun4;

以下程序调试结果为:public class Test {int m=5;public void some(int x) {m=x;}public static void main(String args []) {new Demo().some(7);}}class Demo extends Test {int m=8;public void some(int x) {super.some(x);System.out.println(m);}}A.5B.8C.7D.无任何输出E.编译错误

多选题现有:  public  class  TestDemo{     private int X-2;      static int y=3;  public  void method(){      final int i=100;      int j  =10;     class Cinner {  public void mymethod(){      //Here     }     }     }     } 在Here处可以访问的变量是哪些?()AXByCjDi

多选题public class TestDemo{   private int x = 2;   static int y = 3;   public void method(){   final int i=100;   int j = 10;   class Cinner{   public void mymethod(){  //Here  }  }  }  }   在Here处可以访问的变量是哪些?()AxByCiDj