资源描述
一、选择题1.下列程序所计算的数学式是( )int a=0,i=2;while(i=0;j-)Console.Write(“00”,numsj);Console.WriteLine();答案:108361224241236810 2、classFruit publicstringcolor;publicstringshape;publicFruit(stringc,strings) color=c;shape=s;classTest publicstaticvoidMain() FruitOrange=newFruit(orange,round);Console.WriteLine(0,1,Orange.color,Orange.shape);答案:orange,round 3、usingSystem;classPoint publicintx,y;publicPoint(intx,inty) this.x=x;this.y=y;classTest staticvoidMain() Point p=newPoint(5,6);Console.WriteLine(x=0,p.x);Console.WriteLine(y=0,p.y); 答案:x=5y=64、classDecon1publicDecon1() Console.WriteLine(“调用构造函数Decon1”); Decon1() Console.WriteLine(“调用析构函数Decon1”);classDecon2publicDecon2() Console.WriteLine(“调用构造函数Decon2”);Decon2() Console.WriteLine(“调用析构函数Decon2”); classTest publicstaticvoidMain() Decon1 dec1=newDecon1();Decon2 dec2=newDecon2();答案:调用构造函数Decon1调用构造函数Decon25、using System;classTestpublicvoidmyMeth() intj;for(j=1;j=5) j=j*2;Console.WriteLine(j);return; elsej=j*3;Console.WriteLine(j);return; staticvoidMain()Testlei=newTest();lei.myMeth();答案:167、usingSystem;classTest publicvoidSwap(intx,inty) intk;k=x;x=y;y=k;staticvoidMain() inta=8,b=68;Console.WriteLine(a=0,y=1,a,b);Test sw=newTest();sw.Swap(a,b);Console.WriteLine(a=0,y=1,a,b); 答案:a=8,b=68a=8,b=688、usingSystem;classTestoverLoad publicvoidprint(inti) Console.WriteLine(输出的整数=0,i);publicvoidprint(string s) Console.WriteLine(输出的字符串=0, s); publicvoidprint(doubled) Console.WriteLine(输出的双精度数=0,d); class testpublicstaticvoidMain() TestoverLoad app=newTestoverLoad();app.print(6);app.print(理解方法重载了吗?);app.print(3.14);答案:输出的整数=6输出的字符串=理解方法重载了吗? 输出的双精度数=3.149、classA publicintcount;publicA() count=-1;publicA(intn) count=n; classTest staticvoidMain() Aa=newA();Console.WriteLine(count=0,a.count);Ab=newA(5);Console.WriteLine(count=0,b.count);答案:count=-1count=510、有以下程序,计算结果 staticvoidMain(stringargs) Console.Write(输入一整数);Strings=Console.ReadLine();intnum=int.Parse(s);if(num+5) Console.WriteLine(num);else Console.WriteLine(-num);Console.Read();运行时,从键盘输入5,则输出结果是:5
展开阅读全文