niusouti.com

下列程序的输出结果是( )。 public class Test { public static void main (String[] args) { String s="hello"; s.replace ('r','m'); System.out.println(s); } }A.helloB.HELLOC.hemmoD.HEMMO

题目

下列程序的输出结果是( )。 public class Test { public static void main (String[] args) { String s="hello"; s.replace ('r','m'); System.out.println(s); } }

A.hello

B.HELLO

C.hemmo

D.HEMMO


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

    下列程序的运行结果是______。 include class test { private: int hum; public: tes

    下列程序的运行结果是______。

    include<iostream.h>

    class test

    {

    private:

    int hum;

    public:

    test( );

    int TEST( ){return num+100;)

    ~test( );

    };

    test::test( ){num=0;)

    test::~test( ){cout<<"Destructor is active"<<endl;)

    void main( )

    {

    test x[3];

    cout<<x[1].TEST( )<<endl;

    }


    正确答案:100 Destructor is active Destructor is active Destructor is active
    100 Destructor is active Destructor is active Destructor is active 解析:本题比较简单,考查考生基本的类的定义,构造函数以及对象数组的概念。

  • 第2题:

    下列程序的运行结果是______。include class Base { public: void f(int x){cout<<“B

    下列程序的运行结果是______。

    include<iostream.h>

    class Base

    {

    public:

    void f(int x){cout<<“Base:”<<x<<endl;}

    );

    class Derived:public Base

    {

    public:

    void f(char*str){cout<<“Derived:”<<str<<endl;}

    };

    void main(void)

    {

    Base*pd=ne


    正确答案:Base:97。
    Base:97。 解析: 本题主要考查两个知识点,一是基类指针可以指向派生类对象,并可以访问派生类的所有成员。二是在函数重载中进行隐式类型转换。如pd->f(‘a’);系统到底调用哪个重载函数呢?实参既不是派生类中的形参,也不是基类中f函数的形参类型。此时系统根据就近原则和从高优先级到低优先级的规则尝试隐式转换。单字符更接近整数,故调用的是基类的f函数。

  • 第3题:

    下列程序的输出结果是______。 include using namespace std; class Test( public: Te

    下列程序的输出结果是______。 #include<iostream> using namespace std; class Test( public: Test() {cnt++;} ~Test() {cnt--;} static int Count(){return cnt;} private: static int cnt; }; int Test::cnt=0; int main() { cout<<Test::Count()<<""; Test t1,t2; Test*pT3=new Test; Test*pT4=new Test; cout<<Test::Count()<<""; delete pT4; delete pT3; cout<<Test::Count()<<end1; return 0; }

    A.024

    B.042

    C.420

    D.240


    正确答案:B
    解析:此题考查的是类的构造函数与析构函数的调用。语句 coutTcst::Count()"";;输出“0”,因为static型变量cnt的默认值是0;“T Test t1,t2;Test*pT3=new Test;Test*pT4=new Test;”调用4次类的构造函数,使得cnt的值增加到4,并输出4;然后delete pT4;delete pT3;调用两次析构函数,cnt的值变为2,并输出2。

  • 第4题:

    如下程序的输出结果是includeusing namespace std;class Test{public:Test( ){n+=2;}

    如下程序的输出结果是 #include<iostream> using namespace std; class Test{ public: Test( ){n+=2;} ~Test( ){n-=3;} static int getNum( ){return n;} private: static int n; }; int Test::n=1; int main( ){ Test*P=new Test: delete P; cout<<"n="<<Test::getNum( )<<endl; return 0; }

    A.n=0

    B.n=1

    C.n=2

    D. n=3


    正确答案:A
    解析:静态数据成员的初始值n=1,执行Test*p=new Test;,调用构造函数后,n= 3,deletep;调用析构函数,n-=3,所以最终n=0。

  • 第5题:

    有如下程序:include using namespace std;class Test{public:Test(){n+=2; }~Test(){

    有如下程序: #include <iostream> using namespace std; class Test { public: Test() {n+=2; } ~Test() {n-=3; } static int getNum() {return n; } private: static int n; }; int Test::n=1; int main() { Test* p=new Test; delete p; cout<<"n="<<Test::getNum()<<endl; return 0; } 执行该程序的输出结果是( )。

    A.n=0

    B.n=1

    C.n=2

    D.n=3


    正确答案:A
    解析:此题考查的是静态数据成员和静态成员函数。静态数据成员是类中所有对象共享的成员,而不是某个对象的成员。题目中的静态数据成员n的运算具有叠加性,执行“n+=2”和“n-=3”后n的值为0。

  • 第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里面的实参。