在下列源代码文件Test.java中,哪个选项是正确的类定义? ( )
A.public class test { public int x=0; public test(int x) { this.x=x; } }
B.public class Test { public int x=0; public Test(int x) { this.x=x; } }
C.public class Test extends Ti,T2 { public int x=0; public Test(int x) { this.x=x; } }
D.protected class Test extends T2 { public int x=0; public Test(int x) { this.x=x; } }
第1题:
下列哪个方法可用于创建一个可运行的类? ( )
A.public class X implements Runable {public void run(){...,.,}}
B.public class X implements Thread {public void run(){......}}
C.public class X implements Thread {public int run(){……}}
D.public class X implements Runable {protected void run(){.....}}
第2题:
有如下类定义:
class Point{
public:
Point(int xx=0,int yy=0):x(xx),y(yy) { }
private:
int x,y;
};
class Circle:public Point{
public:
Circle(int r):radius(r) { }
private:
int radius;
};
派生类Circle中数据成员的个数是( )。
A、3
B、1
C、5
D、2
答案:A
解析:本题考查默认构造函数和带参数的构造函数,题目中定义一个对象a(2)以及对象数组b[3],共执行3次构造函数,对象指针不调用构造函数。
第3题:
有如下类定义:
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 . ④
第4题:
下列哪个选项的java源文件代码片段是不正确的?
A.package testpackage; public class Test{ }
B.import java. io. *; package testpaekage; public class Test { }
C.import java.io.*; class Person { } public class Test { }
D.import java.io.*; import java. awt.*; public class Test{ }
第5题:
类Test定义如下,将下列______方法插入③行处是不合法的。 ( )①public class Test{②public float Method(float a,float b){}③④}
A.public float Method(float a,float b,float c){}
B.public float Method(float c,float d){}
C.public int Method(int a,int b){}
D.private float Method(int a,int b,int c){}
第6题:
A.public class test { public int x = 0; public test(int x) { this.x = x; } }
B.public class Test{ public int x=0; public Test(int x) { this.x = x; } }
C.public class Test extends T1, T2 { public int x = 0; public Test (int x) { this.x = x; } }
D.public class
第7题:
下列程序的运行结果是【 】。
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;
}
第8题:
下列关于Test类的定义中,正确的是______。
A) class Test implements Runnabte{
public void run(){}
public void someMethod(){}
B) class Test implements Rnuuable{
public void run();
}
C) class Test implements Rnuuable{
public void someMethod();
}
D) class Test implements Rnuuable{
public void someMethod();{}
}
A.
B.
C.
D.
第9题:
已知有下列类的说明,则下列哪个语句是正确的?public class Test { private float f=1.0f; int m=12; static int n=1; public static void main(String arg[]) { Test t= new Test(); }}
A.t.f;
B.this. n
C.Test.m;
D.Test.f;
第10题:
下列类的定义中,有( )处语法错误。 class Base { public: Base(){} Base(int i) { data=i; } private: int data; }; class Derive : public Base { public: Derive() : Base(0) {} Derive (int x) { d=x; } void setvalue(int i) { data=i; } private: d; };
A.1
B.2
C.3
D.4