计算机二级

下列程序的输出结果是 class Demo { void test( ) { Systeme.out.pnnt("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.test(5)

题目

下列程序的输出结果是 class Demo { void test( ) { Systeme.out.pnnt("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.test(5); de.test(6,8); } }

A.No 5 6 8

B.5 6 8 No

C.No 5 14

D.8 6 No 5

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

第1题:

59、以下程序的输出结果为:()。 void main() { void increment(void); increment(); increment(); increment(); } void increment(void) { int x=0; x++; printf(“%d ”,x); }


B 241/100=2,2%9=2,所以a=2,b为两个非零的值的逻辑与,结果为1,。

第2题:

6 写出下列程序在X86 上的运行结果。

struct mybitfields

{

unsigned short a : 4;

unsigned short b : 5;

unsigned short c : 7;

}test

void main(void)

{

int i;

test.a=2;

test.b=3;

test.c=0;

i=*((short *)&test);

printf("%d\n",i);

}


正确答案:
 

第3题:

下列程序的输出结果是______。includeinclude using namespace std;void

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

include <iostream.h>

include <cstring.h>

using namespace std;

void fun(const char*s,char &C) {c=s[strlen (s)/2];}

int main {)

{

char str [] ="ABCDE";

char ch=str[1];

fun(str,sh);

cout<<Ch;

return 0;

}


正确答案:C
C 解析:本题考核数组的定义、使用以及函数的调用。fun函数的作用是将字符串str中间的字符赋值给地址传入的变量ch。所以ch的值将被修改为‘C’。

第4题:

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

第5题:

publicclassTest {}Whatistheprototypeofthedefaultconstructor?()

A.Test()

B.Test(void)

C.publicTest()

D.publicTest(void)

E.publicvoidTest()


参考答案:C
ThecorrectanswertothisquestionisC.Thedefaultconstructoralwaystakesthesameaccessoftheclass.Inthiscase,theclassispublicandsodoesthedefaultconstructor.

第6题:

下列程序的运行结果是【 】。 include class SomeClass { public: SomeClass(int va

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

include <iostream. h>

class SomeClass

{

public:

SomeClass(int value) { some_value=value;};

void show_data(void) { cout<<data<<"<<~some_value<<endl; };

static void set_data(int value) {data=value; }

private:

static int data;

int some_value

};

int SomeClass::data

void main(void)

{

SomeClass my_class(1001),your_class(2002);

your_class. set_data(4004);

my_elass. show_data()

}


正确答案:4004 1001
4004 1001 解析:本题考查静态成员变量在不同对象间的共享现象。无论哪个对象修改了其静态变量的值,其他对象再访问该变量时已经发生了变化。

第7题:

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

第8题:

下列程序的执行结果是【 】。 include int a; int sum_a(void) { a=a+5; return a; }

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

include <iostream. h>

int a;

int sum_a(void)

{

a=a+5;

return a;

}

void main(void)

{

a = a+sum_a();

cout<<a<<endl;

}


正确答案:10
10 解析:本题考查全局变量的使用。全局变量被系统默认初始化为0,故在执行a=a+sum _a();语句时,首先执行sum_a函数,将a的值改变为5,该函数的返回值也是5,故最后a的值被赋值为10。

第9题:

下列程序的执行结果是______。 include int a; int sum_a(void) { a=a+5; return a;

下列程序的执行结果是______。

include<lostream.h>

int a;

int sum_a(void)

{

a=a+5;

return a;

}

void main(void)

{

a=a+sum_a( );

cout<<a<<endl;

}


正确答案:10
10 解析:本题考查全局变量的使用。全局变量被系统默认初始化为0,故在执行a=a+sum-a( );语句时,首先执行sum_a函数,将a的值改变为5,该函数的返回值也是5,故最后a的值被赋值为10。