下列关于Test类的定义中,正确的是( )。 A.class Test implements Runnable{ public void run{} D

题目

下列关于Test类的定义中,正确的是( )。

A.class Test implements Runnable{ public void run{} Dublic void someMethod[]{} }

B.class Test implements Runnable( puIblic void run; }

C.class Test implements Runnable( Dublic void someMethod[]; }

D.class Test implements Runnable( public void someMethod{} }

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

应在下面程序下划线中填写的正确的语句是( )。 include using namespace std;

应在下面程序下划线中填写的正确的语句是( )。 #include <iostream> using namespace std; class A{ public: void test(){cout<< "this is A!";} }; class B:public A{ void test(){ ______ //显示调用基类函数test() cout<< "this is B!"; } }; void main(){}

A.A::test()

B.test()

C.B::test()

D.this->test()


正确答案:A
解析:A::表示A的作用域。

第2题:

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

第3题:

已知函数tEst定义为:voiDtEst() { ………… }则函数定义中voiD的含义是()

A、执行函数tEst后,函数没有返回值

B、执行函数tEst后,函数不再返回

C、执行函数tEst后,函数返回任意类型值

D、以上三个答案都是错误的


参考答案:A

第4题:

下列关于Test类的定义中,正确的是( )。

A.

B.

C.

D.


正确答案:A
java中实现多线程的方法之-就是实现Runnable接口中的run方法,把实现Runnable接口的子类对象传递给Thread类的构造函数。

第5题:

有如下类定义: class Test { public: Test(){a=0;c=0} //① int f(int a)const{this->a=a;} //② static int g(){return a;} //③ void h(int b){Test::b;}; //④ private: int a; static int b; const int C; }; int Test::b=0; 在标注号码的行中,能被正确编译的是( )。

A.①

B.②

C.③

D.④


正确答案:D
解析:此题考查的是类的定义。一个类的长数据成员的初始化只能在成员初始化列表中进行,故选项A) 错误;常成员函数不能更新对象的数据成员,故选项B) 错误;静态成员函数可以直接访问类中说明的静态成员,但不能直接访问类中说明的非静态成员,故选项C) 错误。

第6题:

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

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

include <iostream. h>

class test

{

private:

int num;

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
100 解析:本题比较简单,考查考生基本的类的定义,构造函数以及对象数组的概念。

第7题:

如果使用Thread t=new Test()语句创建一个线程,则下列叙述正确的是

A.Test类一定要实现Runnable接口

B.Test类一定是Thread类的子类

C.Test类一定是Runnable的子类

D.Test类一定是继承Thread类并且实现Runnable接口


正确答案:B
解析:本题考查线程的使用。Java中可以通过实现Runnable接口来创建线程。通过这种方式创建线程是把Runnable的一个对象作为参数传递给Thread类的一个构造方法,该对象提供线程体run()。如果题目中Test实现Runnable接口,则创建线程的方法是Thread t=new Thread(new Test())。Java中另一种创建线程的方法是通过继承 Thread类,重写其中的run()方法定义线程体,然后直接创建该子类的对象即可创建线程。题目中使用Thread t=new Test()语句创建线程,其中直接创建Test类对象,可知该类一定是继承Thread类。因此,本题的正确答案是选项B。

第8题:

如果使用 Thread t = new Test() 语句创建一个线程,则下列叙述正确的是

A)Test 类一定要实现 Runnable 接口

B)Test 类一定是 Thread 类的子类

C)Test 类一定是 Runnable 的子类

D)Test 类一定是继承 Thread 类并且实现 Runnable 接口


正确答案:D

第9题:

有如下类定义: class Test { public: Test(){a=0;c=0;} //① int f(int a)const {this->a=a;} //② static int g(){return a;} //③ void h(int b){Test::b=b;}; //④ private: int a; static int b; const int c; }; int Test::b=0; 在标注号码的行中,能被正确编译的是

A.①

B.②

C.③

D.④


正确答案:D
解析:本题考查了类的定义。一个类的常数据成员的初始化只能在成员初始化列表中进行,所以选项A不正确。常成员函数不能更新对象的数据成员,所以选项B不正确。静态成员函数可以直接访问类中说明的静态成员,但不能直接访问类中说明的非静态成员,所以选项C也不正确。故应该选择D。

第10题:

【单选题】定义了类选择器test,让段落应用class名为test的类,下列写法正确的是:

A..test{color:red;}

B.#test{color:red;}

C.test{color:red;}

D.,test{color:red;}


A