下列程序的运行结果是______。 Class C14 implements Runnable { private int i; public C14(int n) { this.i = n; } public void run{) { try { Thread.currentThread().sleep(i); } catch(InterruptedException ie) { System.err.println(ie.tString()); } System.out.println("线程" +

题目

下列程序的运行结果是______。 Class C14 implements Runnable { private int i; public C14(int n) { this.i = n; } public void run{) { try { Thread.currentThread().sleep(i); } catch(InterruptedException ie) { System.err.println(ie.tString()); } System.out.println("线程" + Thread.currentThread() .getName + "睡眠了" + i + "毫秒结束"); } } public class Testl4 { public static void main(String[] args) { Thread t = new Thread(new C14(300), "t"); t.start(); } }

A.线程t睡眠了300毫秒结束

B.线程Thread-0睡眠了300毫秒结束

C.线程t睡眠了i毫秒结束

D.线程Thread-0睡眠了i毫秒结束


相似考题
更多“下列程序的运行结果是______。ClassC14implementsRunnable{private int i;public C14(int n) {thi ”相关问题
  • 第1题:

    有以下程序:include using namespace std;class A{private: int x,y;public: void se

    有以下程序: #include <iostream> using namespace std; class A { private: int x,y; public: void set (int i,int j) { x=i; y=j; } int get_y() { return y; } }; class box { private: int length,width; A label; public: void set(int 1,int w, int s,int p) { length=1; width=w; label.set(s,p); } int get_area() { return length*width; } }; int main() { box small; small.set(2,4,1,35); cout<<small.get_area()<<end1; return 0; } 运行后的输出结果是( )。

    A.8

    B.4

    C.35

    D.70


    正确答案:A
    解析:本题考核成员对象的应用。类box的成员函数set()为设置对象的坐标值和对象的长、宽值。成员函数setarea返回该对象的面积。程序最后输出为8。

  • 第2题:

    若有以下程序: include usingnamespace std; class Sample { private: const int n;

    若有以下程序:

    include <iostream>

    using namespace std;

    class Sample

    {

    private:

    const int n;

    public:

    Sample(int i) :n(i) {)

    void print()

    {

    cout<<"n="<<n<<end1;

    }

    };

    int main()

    {

    sample a(10);

    a.print();

    return 0;

    }

    上述程序运行后的输出结果是【 】。


    正确答案:n=10
    n=10 解析:本题考核常成员数据的应用。类Sample中,定义了一个常数据成员n,所以构造函数只能通过初始化列表来初始化它。

  • 第3题:

    下列程序的运行结果是______。 include class Base { public: virtual void func(int

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

    include<iostream.h>

    class Base

    {

    public:

    virtual void func(int i){cout<<"class Base:"<<i<<end1;)

    };

    class Derived: public Base

    {

    public:

    void func(double d){cout<<"class Derived:"<<d<<endl;}

    };

    void main( )

    {

    Base a,*p=a;

    Derived b;

    p=&b;

    (*p).func(3.3);

    }


    正确答案:class Base:3
    class Base:3 解析:题中基类和派生类中有同名函数,但是参数不同。派生关系中,只有在函数类型、函数名和参数个数、参数类型完全相同时,才表现多态性。本题中参数不同,编译器便认为是两个完全不同的函数。通过基类的指针指向派生类对象时,该指针只能访问到派生类中具有多态性的成员函数,而与基类无关的函数是无法通过基类指针来访问的。故调用的是base类的 func函数,系统将3.3强制转化为整型数3。如果将派生类中的func的形参改为int型,则执行的就会是派生类的func函数,此时表现为多态。

  • 第4题:

    分析一下这段程序的输出(Autodesk)

    class B

    {

    public:

    B()

    {

    cout<<"default constructor"<<endl;

    }

    ~B()

    {

    cout<<"destructed"<<endl;

    }

    B(int i):data(i) //B(int) works as a converter ( int ->

    instance of B)

    {

    cout<<"constructed by parameter " << data <<endl;

    }

    private:

    int data;

    };

    B Play( B b)

    {

    return b ;

    }


    正确答案:

     

    (1) results:
    int main(int argc, char* argv[]) constructed by
    parameter 5
    { destructed B(5)形参析构
    B t1 = Play(5); B t2 = Play(t1); destructed t1形
    参析构
    return 0;
    destructed t2 注意顺序!
    } destructed t1
    (2) results:
    int main(int argc, char* argv[]) constructed by
    parameter 5
    { destructed B(5)形参析构
    B t1 = Play(5); B t2 = Play(10); constructed by
    parameter 10
    return 0;
    destructed B(10)形参析构
    } destructed t2 注意顺序!
    destructed t1

  • 第5题:

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

    若有以下程序: #include <iost ream> using namespace std; class A { private: int a; public: A(int i) { a=i; } void disp () { cout<<a<<", "; } }; class B { private:

    A.10,10,10

    B.10,12,14

    C.8,10,12

    D.8,12,10


    正确答案:D
    解析:本题考核派生类构造函数的使用。本题中,派生C具有多重继承关系,所以在派生类C的构造函数中应该包含基类A和B的成员初始化列表。而且派生类C中的成员函数disp分别调用了基类A、B的公有成员函数disp()用于输出基类中私有数据变量初始化后的值。所以由类C构造函数的初始化形式可知,程序最后输出为8,12,10,即D选项。

  • 第6题:

    下列程序的运行结果是______。include int Func(int *a,int n) {int s=1; for(int i=0

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

    include<iomanip.h>

    int Func(int *a,int n)

    {int s=1;

    for(int i=0;i<n;i++)

    s*=*a++;

    returns;}

    void main()

    {inta[]:{1,2,3,4,5,6,7,8};

    intb=Func(a,6)+Func(&a[5],2);

    cout<<“b=“<(b<<endl;}


    正确答案:b=762。
    b=762。 解析: 本题考查了。a++的用法。*a++作为表达式时,先计算*a作为表达式的值,然后使指针变量 a本身增1,在本惠中,s*=*a++等同于3=s**a,a++,S后面第一个*是乘号。