下列程序的输出结果是( )。 public class c3 { public static void main(String args[]) { char c1='B',c2='C'; if(c1+1<c2) ++C1; System.out.println(c1); } }A.BB.bC.CD.c

题目

下列程序的输出结果是( )。 public class c3 { public static void main(String args[]) { char c1='B',c2='C'; if(c1+1<c2) ++C1; System.out.println(c1); } }

A.B

B.b

C.C

D.c


相似考题
更多“下列程序的输出结果是()。public class c3{public static void main(String args[]){char c1='B', ”相关问题
  • 第1题:

    以下程序运行后的输出结果是______。includeinclude usingnamespacestd;classY

    以下程序运行后的输出结果是______。

    include <iostream>

    include <string>

    using namespace std;

    class Y;

    class X

    {

    int x;

    char *strx;

    public:

    X(int a, char *str)

    {

    x=a;

    strx=new char[strlen(str)+1]

    strcpy (strx,str);

    }

    void show(Y &ob);

    };

    class Y

    {

    prlvate:

    int y;

    char *stry;

    public:

    Y(int b,char *str)

    {

    y=b;

    stry=new char[strlen(str)+1];

    strcpy(stry,str);

    }

    friend void X::show(Y &ob);

    };

    void X::show{Y &ob)

    {

    cout<<strx<<",",

    cout<<ob.stry<<endl;

    }

    int main{

    {

    X a (10, "stringX");

    Y b (20, "stringY");

    a. show (b);

    renurn 0;

    }


    正确答案:stringX stringY
    stringX stringY 解析:本题考核友元函数的应用。该程序中,类X的成员函数show()在类Y中说明为类Y的友元函数,因此,在该友元成员show()中可以访问类Y的私有成员stry.成员函数show()的功能就是输出类X的私有成员strx和 Y对象ob的私有成员stry。主函数main()中定义了 X类的一个对象a和Y类的一个对象b,并且都进行了初始化.然后调用对象a的成员函数show,输出对象a中私有成员strx中的内容和对象b中私有成员stry中的内容,即字符串stringX和stringY。

  • 第2题:

    下面程序的输出结果是()。include using namespace std;class A {public:A( ) {cout<<

    下面程序的输出结果是( )。 #include <iostream> using namespace std; class A { public: A( ) {cout<<"A";} } class B { public: B() {coat<<"B" ;} } class C: public A { public: B b; C() {cout<<"C";} } void mian(){ C c; }

    A.CBA

    B.ABC

    C.ACB

    D.BCA


    正确答案:B
    解析:先执行基类A构造函数输出A,调用类B的构造函数输出B,调用本身构造函数输出C。

  • 第3题:

    阅读以下说明和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里面的实参。

  • 第4题:

    已知类 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 个函数


    正确答案:
     

  • 第5题:

    以下程序的输出结果是【 】。includeincludechar*fun(char*t){ char *p=t;retur

    以下程序的输出结果是【 】。

    include <stdio.h>

    include <string.h>

    char *fun(char *t)

    { char *p=t;

    return (p+strlen(t)/2);

    }

    main()

    { char *str="abcdefgh";

    str=ftm(str);

    puts(str);

    }


    正确答案:
    efgh 解析:本题考查的知识点是:字符指针。题目中的fun()函数,通过strlen()库函数得到形参t所指字符串的长度。然后返回t所指字符串首地址值加上该长度值的一半。所以fun()函数的作用就是返回所给字符串的中间位置。故最后通过puts()输出的字符串为"efgh"。

  • 第6题:

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



    【C++代码】
    #include?#include?using?namespace?std;class?DrawCircle?{??????//绘制圆形,抽象类? ? ? public: (1);//定义参数为?int?radius,?int?x,?inty? ?virtual~DrawCircle()?{?}};class?RedCircle:public?DrawCircle?{????//绘制红色圆形? ? ? ? public: void?drawCircle(intradius,?int?x,?int?y)?{cout?<?drawCircle?=?drawCircle;? }? ?virtual~shape()?{?}? public:? ?virtual?void?draw()?=?0;};class?Circle:public?Shape?{????//圆形? ? private:? ? ?int?x,y,radius;? ? public:? Circle(int?x,inty,int?radius,DrawCircle?*drawCircle)? (3)? {? this->x?=?x;? ?this->y?=?y;? ? this->radius?=?radius; }? ? ? public:? void?draw(){? drawCircle?-> (4); }};int?main(){Shape?*redCirclenew?Circle(100,100,10,????(5)????);//绘制红色圆形? Shape?*greenCircle=new?Circle(100,100,10, (6)??);//绘制绿色圆形redCircle >draw();? ?greenCircle?->draw();? ?return?0;}


    答案:
    解析:
    (6)(1)void drawCircle (int radius,int x,int y)
    (2)DrawCircle*drawCircle
    (3)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。
    第三空这里填drawcircle,用-> drawcircle来引用父类的成员。
    第四空调用drawCircle(radius,x,y)方法。
    第五、六空分别创建一个红色圆形对象和一个绿色圆形对象作为Circle里面的实参。