public class test(  public int aMethod()[  static int i=0; 

题目
单选题
public class test(  public int aMethod()[  static int i=0;  i++;  return I;  )  public static void main (String args[]){  test test = new test();  test.aMethod();  int j = test.aMethod();  System.out.printIn(j);  ]  }        What is the result?()
A

 Compilation will fail.

B

 Compilation will succeed and the program will print “0”

C

 Compilation will succeed and the program will print “1”

D

 Compilation will succeed and the program will print “2”

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

第1题:

下面代码段的输出结果为( )。 public class Test { public static void main(String sss[]) { int i=0xFFFFFFFl; int j=~i; } }

A.0

B.1

C.14

D.-15


正确答案:C
解析:本题考查对位运算符的理解和掌握。j的值是将i的值按位取反得到的,所以,将0xFFFFFFF1取反得到0x0000000E,十进制数值为14。故本题答案是C。

第2题:

在如下源代码文件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.public class


正确答案:BD

第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 . ④


正确答案:C

第4题:

类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){ }


正确答案:B

第5题:

下列代码的执行结果是public class Test{ public int aMethod(){ static int i=0; i++; System.out.println(i); } public static void main(String args[]){ Test test= new Test(); test. aMethod(); }}

A.编译错误

B.0

C.1

D.运行成功,但不输出


正确答案:A
解析:static不能修饰局部变量。

第6题:

下面程序的运行结果是【】。 include using namespace std; class count{ static int n;

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

include <iostream>

using namespace std;

class count

{

static int n;

public:

count()

{

n++;

}

static int test()

{

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

n++;

return n;

}

};

int count::n = O;

int main()

{

cout<<count:: test()<<" ";

count c1, c2;

cout<<count:: test()<<endl;

return 0;

}


正确答案:410
410 解析:本题主要考查C++类中静态数据成员的使用。题目程序首先定义了类count,其内部含有private 类型数据成员static int n;同时含有public 类型构造函数 count()和静态成员函数static int test(),这两个函数的功能分别是为对象申请系统资源并将静态数据成员n加1和将静态数据成员n加4。主函数前,程序将静态数据成员n初始化为0,该数据成员为所有类count 的对象所共有的数据成员;主函数中程序首先执行静态成员函数test() (由于test 声明为 static,因此其调用时无需通过具体对象),其执行过程中,静态数据成员n应该加4变成n:4,因此此处输出为4;此后程序创建对象c1和c2,由于在每次创建过程中都要调用构造函数count(),而每次调用count()函数后,静态数据成员n值都会加1。因此,创建两个对象之后,n值变为n=6:再次执行test()函数后,n的值再次加4,因此变为n=6+4=10。故程序全部执行后,变量n值变为10,而中间程序输出为“410”。

第7题:

下列程序的执行结果是 ( ) public class Test { public int aMethod() { satic int i=0; i++; System.out.println(i); } public static void.main(String args[]) { Test test=new Test(); test.aMethod(); }

A.编译错误

B.0

C.1

D.运行成功,但不输出


正确答案:A

第8题:

下面程序的运行结果是【】。 inChlde using namespace std; class count { static int n;

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

inChlde<iOStream>

using namespace std;

class count

{

static int n;

public:

count()

{

n++;

}

static int test()

{

for(int i=0:i<4;i++)

n++;

return n;

}

};

int count::n=0;

int main()

{

cout<<COUnt::test()<<" ";

count c1, c2;

cout<<count::test()<<end1;

return 0;

}


正确答案:4 10
4 10 解析:本题主要考查C++类中静态数据成员的使用。题目程序首先定义了类count,其内部含有private类型数据成员static int n;同时含有public类型构造函数count()和静态成员函数static int test(),这两个函数的功能分别是为对象申请系统资源并将静态数据成员n加1和将静态数据成员n加4。主函数前,程序将静态数据成员n初始化为0,该数据成员为所有类count的对象所共有的数据成员:主函数中程序首先执行静态成员函数test()(由于test声明为static,因此其调用时无需通过具体对象),其执行过程中,静态数据成员n应该加4变成n=4,因此此处输出为4:此后程序创建对象c1和c2,由于在每次创建过程中都要调用构造函数count(),而每次调用 count()函数后,静态数据成员n值都会加1因此,创建两个对象之后,n值变为n= 6:再次执行test()函数后,n的值再次加4,因此变为n=6+4=10。故程序全部执行后,变量n值变为10,而中间程序输出为“410”。

第9题:

在下列源代码文件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; } }


正确答案:B
解析:本题主要考查类声明格式为[修饰符]class类名[extends父类名][implements类实现的接口列表],选项A中源文件名与程序名不相同,Java不支持多重继承所以选项C错误,选项D中类的访问权限不对,应为public。

第10题:

有以下程序:include using namespace std;class count{ static int n;public: count

有以下程序: #include <iostream> using namespace std; class count { static int n; public: count ( ) { n++; } static int test() { for (int i = 0; i < 4; i++ ) n++; return n; } }; int count :: n = 0; int main() { cout<<count :: test()<<" "; count c1, c2; cout<<count :: test()<<end1; return 0; } 执行后的输出结果是( )。

A.4 10

B.1 2

C.22

D.24


正确答案:A
解析:程序首先定义了类count,其内部含有private类型数据成员“staticintn;”,同时含有public类型构造函数count()和静态成员函数staticinttest(),这两个函数的功能分别是为对象申请系统资源并将静态数据成员n加1和将静态数据成员n加4。主函数前,程序将静态数据成员n初始化为0,该数据成员为所有类count的对象所共有的数据成员。主函数中,程序首先执行静态成员函数test()(由于test声明为static,因此其调用时无需通过具体对象)。而其执行过程中,静态数据成员n应该加4变成n=4,因此此处输出为4。此后程序创建对象c1和c2,由于在每次创建过程中都要调用构造函数count(),而每次调用count()函数后,静态数据成员n值都会加1,因此,创建两个对象之后,n值变为n=6;再次执行test()函数后,n的值再次加4,此时变为n=6+4=10。故程序全部执行后,变量n值变为10,而中间程序输出为“410”。

更多相关问题