计算机二级

下列程序的输出结果是 ( ) class Derao { void test() { Systeme.out.print("NO");} void test (int i) {System.out.print(a);} void test(int a,int b) {System.out.print(a+b);} } class Test { public static void main(String args[]) { Demo de=new Demo(); de.test(); de.test5.;

题目

下列程序的输出结果是 ( ) class Derao { void test() { Systeme.out.print("NO");} void test (int i) {System.out.print(a);} void test(int a,int b) {System.out.print(a+b);} } class Test { public static void main(String args[]) { Demo de=new Demo(); de.test(); de.test5.; de.test(6,8); } }

A.No568

B.568No

C.No514

D.86No5

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

第1题:

下列程序段的输出结果是【 】。

public class Test {

void printValue(int m) {

do {

System.out.println("The value is"+m);

}while (--m>10);

}

public static void main (String args[]) {

int i=10;

Test t= new Test();

t.printValue(i);

}

}


正确答案:Thevalue is 10
Thevalue is 10 解析:本题考查do-while循环的用法。do-while至少执行一次,在执行完do中的内容后,判断while中的条件是否为true。如果为true,就再执行do中的内容,然后再进行判断。依次类推,直到while的判断为false时退出循环,执行循环后面的内容。题目中m的值为10,当程序运行到do-while循环时,程序先执行一次循环然后再作判断,在判断条件--m>10时,其值为false,退出循环。因此只执行了一次输出操作,输出内容为:The value is 10。

第2题:

下面程序段的输出结果是( )。 public class Test { public static void main ( String[] args) { int result=0; for ( int i=1;i<=5;i++) { if ( i%2==0 ) continue; result + =i; } System. out. println ("result is " + result ); } }

A.result is 7

B.result is 8

C.result is 9

D.result is 10


正确答案:C
解析:continue语句跳过循环体中下面尚未执行的语句,回到循环体的开始继续下轮循环。所以题目中程序实现的是求1到5的所有奇数的和,即1+3+5=9,所以选C。

第3题:

下列程序的输出结果为012,请根据注释将横线处的缺失部分补充完整。 include using name

下列程序的输出结果为012,请根据注释将横线处的缺失部分补充完整。

include<iostream>

using namespace std;

class Test{

public:

Test(int A) {data=a;}

~Test(){}

void print(){cout<<data;)

private:

int data;

};

int main(){

Test t[3]={______};//对有3个元素的Test类对象数组t初始化

for(int i=0; i<3; i++) t[i]. print();

return 0;

}


正确答案:012
0,1,2

第4题:

下列程序的执行结果是 ( ) 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

第5题:

根据输出结果填空完成下面程序。 include class Test { private: static int val; in

根据输出结果填空完成下面程序。

include<iostream.h>

class Test

{

private:

static int val;

int a;

public:

static int func( );

void sfunc(Test &r);

};

______//初始化静态变量val

int Test::func( )

{

return val++;

}

void Test::sfunc(Test &r)

{

r.a=125;

cout<<"Result3="<<r.a;

}

void main( )

{

cout<<"Resultl="<<Test::func( )<<endl;

Test A;

cout<<"Result2="<<A.fune( )<<endl;

A. sfunc(A);

}

输出结果为:

Result1=201

Result2=202

Result3=125


正确答案:int Test::val=200;
int Test::val=200; 解析:类的静态成员变量必须要进行初始化才能使用,初始化时需要用域限定符::指明该变量所属的类名。

第6题:

如下程序的输出结果是( )。 public class Test { void printValue(int m) { do { System.out.println("The value is"+m); } while( --m>10) } public static void main(String args[]) { int i=10; Test t=new Test(); t.printValue(i); } }

A.The value is 8

B.The value is 9

C.The value is 10

D.The value is 11


正确答案:C
解析:此题考查的是do-while循环和“--”操作符的知识。do-while最少执行一次,在执行完do中的内容后,判断while中的条件是否为true。如果为true,就再执行do中的内容,然后再进行判断。以此类推,直到while的判断为false时退出循环,执行循环后面的内容。而“--”操作符的规则是,变量右边的“--”将先进行运算,然后才使变量的值减一。而在变量左边的“--”,则先将变量的值减一再运算。本程序中I的值为10,当程序运行到do-while循环时,程序先执行一次循环后然后再做判断,因此选C。

第7题:

下列关于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.


正确答案:A

第8题:

若下面程序运行时输出结果为

1, A, 10.1

2, B, 3.5

请将程序补充完整 。

#include

using namespace std;

int main()

{

void test(int, char,double 【 8 】 );

test(1,'A',10.1);

test(2,'B');

return 0;

}

void test(int a, char b, double

C .

{

cout<

}


正确答案:

第9题:

下面程序的输出结果是什么? class C1{ static int j=0; public void method(int a){ j++; } } class Test extends C1{ public int method(){ return j++; } public void result(){ method(j); System.out.println(j+method()); } public static void main(String args[]){ new Te

A.0

B.1

C.2

D.3


正确答案:C

第10题:

下列程序的输出结果是_______。

class Test{

public static void main(String args []){

int m=6;

do{m--:}while(m>0);

System.out.println("m="+m);

}

}


正确答案:×
0

更多相关问题