niusouti.com

public class Pass{public static void main(String[]args){int x=5;Pass p=new Pass();p.doStuff(x);System.out.print("mainx="+x);}void doStuff(intx){System.out.print("doStuffx="+x++);}}What is the result?()A.Compilation fails.B.An exception is thrown at runtim

题目

public class Pass{public static void main(String[]args){int x=5;Pass p=new Pass();p.doStuff(x);System.out.print("mainx="+x);}void doStuff(intx){System.out.print("doStuffx="+x++);}}What is the result?()

A.Compilation fails.

B.An exception is thrown at runtime.

C.doStuff x=6 main x=6

D.doStuff x=5 main x=5

E.doStuff x=5 main x=6

F.doStuff x=6 main x=5


相似考题
更多“public class Pass{public static void main(String[]args){int x=5;Pass p=new Pass();p.doStuf ”相关问题
  • 第1题:

    对于下面程序,对p进行赋值正确的是( )。 class A{ public:fun(int i){cout<<i<<endl;} }; main(){ void(A::*p)(int); }

    A.p=fun;

    B.p=fun();

    C.p=A::fun;

    D.p=A::fun()


    正确答案:C
    解析:给类函数指针赋值的格式是:指针名>=类名::函数名>

  • 第2题:

    A user wants to establish an FTP session to a server behind an SRX device but must authenticate to a Web page on the SRX device for additional authentication.Which type of user authentication is configured?()

    A. pass-through

    B. WebAuth

    C. WebAuth with Web redirect

    D. pass-through with Web redirect


    参考答案:B

  • 第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题:

    下面程序段中的错误语句是 ______。 class M{ int i; public: void ~AA(int); AA *p; void AA(); void AA(int x){i=x;}; };

    A.AA *p;

    B.void ~AA(int);

    C.void AA(int);

    D.void AA(int x){i=x;};


    正确答案:B

  • 第5题:

    A user wants to establish an HTTP session to a server behind an SRX device but is being pointed to Web page on the SRX device for additional authentication.Which type of user authentication is configured?()

    A. pass-through with Web redirect

    B. WebAuth with HTTP redirect

    C. WebAuth

    D. pass-through


    参考答案:A

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