下列程序的运行结果是( )。 public class test{ private String[]data={¨10","10.5"); public void fun{ double s=0: for(int i=0;i<3;j++){ try{ s=s+Integer.parseInt(data[i]); catch(Exception e){ System.out.print("errorl:"+data[i]); } } } public static void main(string[]arg

题目

下列程序的运行结果是( )。 public class test{ private String[]data={¨10","10.5"); public void fun{ double s=0: for(int i=0;i<3;j++){ try{ s=s+Integer.parseInt(data[i]); catch(Exception e){ System.out.print("errorl:"+data[i]); } } } public static void main(string[]args){ try{ test d=new test: fun: }catch(Exception e){ System.OUt.println("error2") } } }

A.errorl:10.5

B.error2

C.errorl:10.5 error2

D.以上都不对


相似考题
参考答案和解析
正确答案:C
C。【解析】try-catch块是可以嵌套分层的,并且通过异常对象的数据类型来进行匹配,以找到正确的catchblock异常错误处理代码。以下是通过异常对象的数据类型来进行匹配找到正确的catchblock的过程。①首先在抛出异常的try-catch块中查找catchblock,按顺序先与第一个catchblock块匹配,如果抛出的异常对象的数据类型与catchblock中传入的异常对象的临时变量(就是catch语句后面参数)的数据类型完全相同,或是它的子类型对象,则匹配成功,进入到catchblock中执行,否则到第2步;②如果有两个或更多的catchblock,则继续查找匹配第二个、第三个,直至最后一个catchblock,如匹配成功,则进入到对应的catchblock中执行,否则到第3步;③返回到上一级的try-catch块中,按规则继续查找对应的catchblock。如果找到,进入到对应的catchblock中执行,否则到第4步;④再到上上级的try-catch块中,如此不断递归,直到匹配到顶级的try-catch块中的最后一个catchblock,如果找到,进入到对应的catchblock中执行;否则程序将会执行terminate退出。所以本题选C。
更多“下列程序的运行结果是( )。 public class test{ private String[]data={¨10","10.5"); publi ”相关问题
  • 第1题:

    下列程序的运行结果是【 】。 include class SomeClass { public: SomeClass(int va

    下列程序的运行结果是【 】。

    include <iostream. h>

    class SomeClass

    {

    public:

    SomeClass(int value) { some_value=value;};

    void show_data(void) { cout<<data<<"<<~some_value<<endl; };

    static void set_data(int value) {data=value; }

    private:

    static int data;

    int some_value

    };

    int SomeClass::data

    void main(void)

    {

    SomeClass my_class(1001),your_class(2002);

    your_class. set_data(4004);

    my_elass. show_data()

    }


    正确答案:4004 1001
    4004 1001 解析:本题考查静态成员变量在不同对象间的共享现象。无论哪个对象修改了其静态变量的值,其他对象再访问该变量时已经发生了变化。

  • 第2题:

    下面程序的结果是 include class test{private: int num; publi

    下面程序的结果是 #include<iostream.h> class test{ private: int num; public: test( ); int getint( ) {return num;} ~test( );}; test::test( ) { num=0;} test::~test( ) { cout<<"Destructor is active"<<endl;} void

    A.Exiting main Destructor is active Destructor is active Destructor is active

    B.Exiting main Destructor is active Destructoris active

    C.Exiting main Destructoris active

    D.Exiting main


    正确答案:A
    解析:C++语言中析构函数是在程序退出不用该类的对象时进行调用。

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

    下列程序的运行结果是______。 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 解析:本题比较简单,考查考生基本的类的定义,构造函数以及对象数组的概念。

  • 第5题:

    下列程序的运行结果是( )。 public class test{ private String[]data={¨10","10.5"}, public void fun( double S=0; for(int i=0;i<3;i++){ try{ s=s+Integer.parseInt(data[i]); catch(Exception e){ System.out.print(“errorl:”+data[i])。 } } } public static void main(string[]args){ try{ test d=new test; fun; }catch(Exception e){ System.out.println("error2") } } }

    A.errorl:10.5

    B.error2

    C.errorl:10.5 error2

    D.以上都不对


    正确答案:C
    C。【解析】try-catch块是可以嵌套分层的,并且通过异常对象的数据类型进行匹配,以找到正确的catchblock异常错误处理代码。以下是通过异常对象的数据类型进行匹配找到正确的catchblock的过程。①首先在抛出异常的try-catch块中查找catchblock,按顺序先与第一个catchblock块匹配,如果抛出的异常对象的数据类型与catchblock中传入的异常对象的临时变量(就是catch语句后面参数)的数据类型完全相同,或是它的子类型对象,则匹配成功,进入catchblock中执行,否则到第②步;②如果有两个或更多的catchblock,则继续查找匹配第二个、第三个,乃至最后一个catchblock,如匹配成功,则进入对应的catchblock中执行,否则到第③步;③返回到上一级的try-catch块中,按规则继续查找对应的catchblock。如果找到,进入对应的catchblock中执行,否则到第4步;④再到上上级的try-catch块中,如此不断递归,直到匹配到顶级的try-catch块中的最后一个catchblock,如果找到,进入到对应的catchblock中执行;否则程序将会执行terminate退出。所以选C。