1.public classA{2.public String doit(intx,inty){3.return"a";4.}5.6.public String doit(int...vals){7.return"b";8.}9.}And:25.A a=new A();26.System.out.println(a.doit(4,5));What is the result?()A.Line 26 prints "a" to System.out.B.Line 26 prints "b" to Syste

题目

1.public classA{2.public String doit(intx,inty){3.return"a";4.}5.6.public String doit(int...vals){7.return"b";8.}9.}And:25.A a=new A();26.System.out.println(a.doit(4,5));What is the result?()

A.Line 26 prints "a" to System.out.

B.Line 26 prints "b" to System.out.

C.An exception is thrown at line 26 at runtime.

D.Compilation of class A will fail due to an error in line 6.


相似考题
更多“public classA{2.public String doit(intx,inty){3.return"a";4.}5.6.public String ”相关问题
  • 第1题:

    若有以下程序:include using namespace std;class A{private:int a;public:void seta

    若有以下程序:#include <iostream>using namespace std;class A{private: int a;public: void seta(int x) { a=x; } void showa() { cout<<a<<","; }};class B{private: int b;public: void setb(int x) { b=x; } void showb() { cout<<b<<","; }};class C: public A, private B{private: int c;public: void setc(int x, int y, int z) { c=z; seta(x); setb(y); } void showc() { showa(); showb(); cout<<c<<end1; }};int main(){ C c; c.setc(1,2,3); c.showc(); return 0;}程序执行后的输出结果是( )。

    A.1,2,3

    B.1,1,1

    C.2,2,2

    D.3,3,3


    正确答案:A

  • 第2题:

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

    下面程序输出的结果是( )。 #include<iostream> using namespace std; class A{ int X; public: A(int x):x(++x){} ~A(){cout<<x;} }; class B:public A{ int y; public: B(int y):A(y),y(y){} ~B(){cout<<y;}; }; void main(){ B b(3); }

    A.34

    B.43

    C.33

    D.44


    正确答案:A
    解析:对象创建的次序为:先基类,后派生类;析构时,先派生类,后基类。

  • 第3题:

    运行下面程序时,会产生什么异常?() public class X7_1_5 { public static void main(String[] args) { int[] z = {1,2,3,4}; int p = z[4]; int x = 0; int y = p/x; } }

    A.ArithmeticException

    B.ArrayIndexOutOfBoundsException

    C.NumberFormatException

    D.IOException


    C

  • 第4题:

    请找出下列程序中错误之处 ______。 include classA{private: intx1;protected: int

    请找出下列程序中错误之处 ______。

    #include<iostream.h>

    class A{

    private:

    int x1;

    protected:

    int x2;

    public:

    int x3;

    };

    class B:public A{

    private:

    int y1;

    protected:

    int y2;

    public:

    int y3;

    void disp(){cout<<x1<<y1<<end1:} //A

    void set(int i) {x2=i;} //B

    };

    void main() {

    B bb;

    bb.x3=10; //C

    bb.y3=10; //D

    }

    A.A

    B.B

    C.C

    D.D


    正确答案:A

  • 第5题:

    若有以下程序:include using namespace std;class A{private: int a;public: void se

    若有以下程序: #include <iostream> using namespace std; class A { private: int a; public: void seta(int x) { a=x; } void showa,( ) { cout<<a<<", "; } }; class B { private: int b; public: void setb(int x) { b=x; } void showb () { cout<<b<<", "; } }; class C : public A, private B { private: int c; public: void setc(int x,int y, int z) { c=z; sera (x); seth (y); } void showc() { showa(); showb(); cout<<c<<end1; } }; int main () { C c; c.setc(1,2,3); c.showc(); return 0; } 程序执行后的输出结果是( )。

    A.1,2,3

    B.1,1,1

    C.2,2,2

    D.3,3,3


    正确答案:A
    解析:本题考核派生类的应用。本题中类A和类B都是基类。而类C从类A公有派生,从类B处私有派生。所以类C中的函数成员可以访问类A和类B中的公有成员。在类C的函数成员setc()中,调用基类A的函数成员seta()对A的数据成员a赋值,还调用了基类B的函数成员setb()对类B的数据成员b赋值,然后对类C自己的数据成员c赋值。在类C的函数成员showc()中,调用基类A的函数成员showa()显示数据成员a的值,还调用基类B的函数成员showb()显示数据成员b的值,然后输出类C自己的数据成员c的值。在主函数中,先定义派生类的对象c,然后调用setc()对c中的数据成员赋值,然后输出赋值结果。所以程序最后输出应该为:1,2,3。

  • 第6题:

    运行下面程序时,会产生什么异常?() public class X7_1_5 { public static void main(String[] args) { int[] z = {1,2,3,4}; int p = z[4]; int x = 0; int y = 5/x; } }

    A.NumberFormatException

    B.ArrayIndexOutOfBoundsException

    C.IOException

    D.ArithmeticException


    C