在下列源代码文件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 T1 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题:
有如下类定义:
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次构造函数,对象指针不调用构造函数。
第2题:
类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){}
第3题:
下列哪个选项的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{ }
第4题:
类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){}
第5题:
在下列源代码文件Test.java中,正确定义类的代码是( )。
A.pblic 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.protected class Test extends T2{ public int x = 0; public Test(int x) { this. x = x; } }
第6题:
有如下类定义: class Test { private int x; public int y; public void setX (int m) {x=m;} public int getX( ) {return x;} }现用Test t=new Text();生成一个对象t,则如下语句中,错误的是( )。
A.t.x=10;
B.t.y=10;
C.t. setX(10);
D.int m=t.getX( );
第7题:
类testl定义如下: public class test1 { public float amethod(float a,float b){ } }
A.public foat amethod(float a,float b,foat c){ }
B.public float amethod(float c,float d){ }
C.public int amethod(int a,int b){ }
D.private float amethod(int a,int b,int c){ }
第8题:
类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) { }private float Method(int a,int b,int C) { }
D.private float Method(int a,int b,int C) { }
第9题:
有如下类定义: class Test { int x_,y_; public: Test ():a_(0) ,b_(0) {} Test(int a,int b=0) :a_(a),b_(b){} }; 若执行语句 Test x(2) ,y[3],*z[4]; 则Test类的构造函数被调用的次数是( )。
A.2次
B.3次
C.4次
D.5次
第10题:
在下列源代码文件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; } }
第11题:
下列类的定义中正确的是()
第12题:
protected void change(int x){}
public void change(int x, int y){}
public void change(String s){}
public void change(int x){}
第13题:
下列程序的运行结果是【 】。
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;
}
第14题:
已知有下列类的说明,则下列哪个语句是正确的?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;
第15题:
下列类的定义中,有( )处语法错误。 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
第16题:
下列哪个选项不是InputStream类中的方法?
A.public abstract int read()throws IOException
B.public final void writeInt (int v)throws IOException
C.public void close()throws IOException
D.public int available() throws IOException
第17题:
类Test定义如下,将下列( )方法插入③行处是不合法的。 ①publicClass Test{ ②public float Method(floatA,float b){} ③ ④}
A.public float Method(floatA,float b,floatC){}
B.public float Method(noatC,float d) {}
C.public int Method(intA,int b){}
D.private float Method(intA,int b,intC){}
第18题:
有如下类定义: 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.④
第19题:
下列哪个选项的java源文件程序段是不正确的? ( )
A.package testpackage; public class Test{ }
B.import java.io.*; package testpackage; public class Test{ }
C.import java.i.*; class Person{} public class Test{ }
D.import java.io.*; import java.awt.*; public class Test { }
第20题:
有如下类定义: class Test { public: Test{a=0;c=0;}//① int f(im A.const{this->a=a;}//② static int g{return a;f//③ void h(int B.{Test:.b=b;};//④ private: int a; static int b; const int C; }; int Test::b=0: 在标注号码的行中,能被正确编译的是( )。
A.①
B.②
C.③
D.④
第21题:
在下列源代码文件Test.java中, ( )是正确的类定义。
A.public class test{
B.public class Test{ public int x=0;public int x=0; public test (intx) public Test (int x){ {this.x=x; this.x=x;} }} }
C.public class Test extends T1,T2{
D.protected class Test extends T2{ public int=0;public int x=0; public Test(int x){Public Test (int x){ this.x=x;this.x=x: }} }}
第22题:
给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载。public class Test { public void cal(int x, int y, int z) { } //A }
第23题:
类Test1定义如下: 1.public class Test1{ 2. public float aMethod(float a,float b){ return 0;} 3. 4.} 将以下哪种方法插入行3是不合法的。()
第24题:
protected void change (int x){}
public void change(int x, int y){}
public void change (int x){}
public void change (String s){}