niusouti.com

有下列程序段 public class fun { public static void main(String args[]) { char b[]="Hello,you"; b[5] = 0; System.out.println(s); } 执行此程序后,得到的输出结果是( )。A.Hello, youB.Hello0youC.HelloD.0

题目

有下列程序段 public class fun { public static void main(String args[]) { char b[]="Hello,you"; b[5] = 0; System.out.println(s); } 执行此程序后,得到的输出结果是( )。

A.Hello, you

B.Hello0you

C.Hello

D.0


相似考题
更多“有下列程序段public class fun{ public static void main(String args[]) {char b[]="Hello,you" ”相关问题
  • 第1题:

    有以下程序段#include <stdio.h>void fun(char*fname,char*st){ FILE * myf; int i; myf=fopen(fname,"w"); for(i=0;i<strlen(st);i++)fputc(st[i],myf); fclose(myf);}main(){ fun("test.t","new world"); fun("test.t","hello,");}程序执行后,文件test.t中的内容是A.hello, B.new worldhello,C.new world D.hello,rld


    正确答案:D
    本题主要考查文件的操作。在本题的程序中,首先定义了一个无返回值的函数fun,该函数带有两个指针类型的形参,其中第一个形参指向需要被操作文件的文件名,而第二个形参指向被操作的字符串。在函数体中,首先定义一个文件指针,然后以只写的方式打开第一个形参所指向的文件,接着执行for循环,循环结束的条件是循环变量小于被操作字符串的长度,循环体中的程序fputc(st[i],myf);的功能是将字符串中的当前字符输入到文件中。由这些分析我们可以知道,函数fun的作用是将字符串的内容写入到文件中。
    在主函数中,两次调用函数fun,当第一次调用时,写入文件的内容为new world,然后第二次调用函数,此时打开文件,文件的指针重新回到开始,然后往文件中写内容“hello,”,由于此时文件中已经有内容“new world”,则需要覆盖前面一部分的内容,因此,程序的最终输出结果是hello,rld,本题的正确答案选D。

  • 第2题:

    已知类 String 的原型为

    class string

    {

    public:

    string(const char *str=null);//普通构造函数

    string(const string &other);//拷贝构造函数

    ---string(void);

    string &operate=(const string &other);//赋值函数

    private:

    char * m-data;//用于保存字符串

    };

    请编写 string 的上述4 个函数


    正确答案:
     

  • 第3题:

    对于下面程序,对p调用正确的是( )。 class A{ public:fun(int i){cout<<i<<endl;} }; main(){ A a; int k=0; void(A::*p)(int); p=A::fun; }

    A.a.p(k);

    B.*a.p(k)

    C.a.*p(k)

    D.a::*p(k)


    正确答案:C
    解析:使用类函数指针格式是:对象名.*指针名>=(实参表)>

  • 第4题:

    将下面程序补充完整。 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;

    }


    正确答案:virtual int Derived::
    virtual int Derived:: 解析:virtual int用于声明虚函数;Derived::用于指定类Derived成员函数。

  • 第5题:

    下面程序的结果是 ______。includeclass A{ public:virtual voidfun()=0{};};class

    下面程序的结果是 ______。 #include<iostream.h> class A{ public: virtual void fun()=0{}; }; class B:public A{ public: void fun () {cout<< "new file" ;} }; class C: public A{ public: void fun (){cout<<"open file"<< " " } }; class D: public A{ public: void fun () {cout<< "save file\n" ;} }; void main() { A a,*p; B b; C c; D d; p=&c; p->fun (); p=&b; p->fun (); p=&d; p->fun(); }

    A.new file open file save file

    B.new file new file new file

    C.编译出错

    D.open file new file save file


    正确答案:C

  • 第6题:

    阅读以下说明和Java程序,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。
    【说明】
    以下Java代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分接口、类及其关系如图5-1所示。




    【Java代码】
    interface?DrawCircle?{? //绘制圆形 public(1) ;}class?RedCircle?implements?DrawCircle?{? ?//绘制红色圆形???????public?void?drawCircle(int?radius,intx,?int?y)??{????????????System.out.println("Drawing?Circle[red,radius:"?+?radius?+",x:"?+?x?+?",y:"?+y+?"]");???????}}class?GreenCircle?implements?DrawCircle?{????//绘制绿色圆形??????public?void?drawCircle(int?radius,?int?x,int?y)?{???????????System.out.println("Drawing?Circle[green,radius:"?+radius+",x:?"?+x+?",y:?"?+y+?"]");??????}}abstract?class?Shape?{????//形状? protected? ? (2)???;? ? public?Shape(DrawCircle?drawCircle)?{? ?this.drawCircle=?drawCircle;? ? ? public?abstract?void?draw();}class?Circle?extends?Shape?{? //圆形? ?private?int?x,y,radius;? public?Circle(int?x,int?y,intradius,DrawCircle?drawCircle)?{? ?(3)???;? this.x?=?x;? ? ? this.y?=?y;? ?this.radius?=radius;? }? ? ?public?void?draw()?{? ? drawCircle.? ?(4)? ?;? ? ? }}public?class?DrawCircleMain?{? public?static?void?main(String[]?args)?{? Shape?redCircle=new?Circle(?100,100,10,? (5) );//绘制红色圆形? Shape?greenCircle=new?Circle(200,200,10,(6) );//绘制绿色圆形? ?redCircle.draw(); greenCircle.draw();? ?}}


    答案:
    解析:
    (1)void drawCircle (int radius,int x,int y)
    (2)DrawCircle drawCircle
    (3)super.drawcircle=drawcircle
    (4)drawCircle(radius,x,y)
    (5)new RedCircle()
    (6)new GreenCircle()【解析】
    第一空是填接口里面的方法,在接口的实现里面找,可以发现应该填void drawCircle (int radius,int x,int y)。
    第二空可以根据后面this drawCircle=drawCircle判断,这里应该有一个drawCircle属性,因此应该填)DrawCircle drawCircle。
    第三空这里用super,用super. drawcircle来引用父类的成员。
    第四空调用drawCircle(radius,x,y)方法。
    第五、六空分别创建一个红色圆形对象和一个绿色圆形对象作为Circle里面的实参。