MyDogSex.docx
- 文档编号:27228029
- 上传时间:2023-06-28
- 格式:DOCX
- 页数:14
- 大小:21.66KB
MyDogSex.docx
《MyDogSex.docx》由会员分享,可在线阅读,更多相关《MyDogSex.docx(14页珍藏版)》请在冰豆网上搜索。
MyDogSex
My,Dog,Sex
篇一:
解析JAVA程序设计第三章课后答案
第3章习题解答
1.如何定义方法?
在面向对象程序设计中方法有什么作用?
答:
方法的定义包括方法名、方法形参、方法的返回值类型和方法体四部分,方法只能在类中定义。
方法是对象的动态特征的描述,对象通过方法操作属性,进而改变对象的状态,完成程序所预期的功能。
2.定义一个Dog类,有名字、颜色、年龄等属性,定义构造方法用来初始化类的这些属性,定义方法输出Dog的信息。
编写应用程序使用Dog。
答:
publicclassDog{
privateStringname;
privateStringcolor;
privateStringage;
Dog(Stringn,Stringc,Stringa){
name=n;color=c;age=a;
}
publicStringtoString(){
returnname+","+color+","+age;
}
publicstaticvoidmain(Stringargs[]){
Dogdog=newDog("小白","白色","2岁");
System.out.println(dog.toString());
}
}
3.什么是访问控制修饰符?
修饰符有哪些种类?
它们各有何作用?
答:
访问控制修饰符是对类、属性和方法的访问权限的一种限制,不同的修饰符决定了不同的访问权限。
访问控制修饰符有
3个:
private、protected、public,另外还有一种默认访问权限。
各个修饰符的作用如下表所示:
B:
包中的类
C:
所有子类
D:
本类
A:
所有类
4.阅读程序,写出程序的输出结果
classA{
privateintprivateVar;
A(int_privateVar){
privateVar=_privateVar;
}
booleanisEqualTo(AanotherA){
if(this.privateVar==anotherA.privateVar)
returntrue;
else
returnfalse;
}
}
publicclassB{
publicstaticvoidmain(Stringargs[]){
Aa=newA
(1);
Ab=newA
(2);
System.out.println(a.isEqualTo(b));
}
}
程序的输出结果为:
false
5.阅读程序,写出程序的输出结果
publicclassTest{
publicstaticvoidmain(String[]args){
intx;
inta[]={0,0,0,0,0,0};
calculate(a,a[5]);
System.out.println("thevalueofa[0]is"+a[0]);
System.out.println("thevalueisa[5]is"+a[5]);
}
staticintcalculate(intx[],inty){
for(inti=1;i if(y x[i]=x[i-1]+1; returnx[0]; } } 程序的输出结果为: thevalueofa[0]is0 thevalueisa[5]is5 6.阅读程序,写出程序的输出结果 publicclassTest{ publicstaticvoidmain(String[]args){ Stringstr1=newString("Java"); Stringstr2=newString("Java"); System.out.println(str1==str2); } } 程序的输出结果为: false 7.阅读下列程序,程序中已经指明错误位置,请说出错误原因。 1. packagesample; classA{ privateintnum; A(){ num=0; } intget(){returnnum;} } classZ{ publicstaticvoidmain(String[]args){ Aa1=newA(); intt=a1.get(); ints=a1.num;//此处有错误 } } 错误原因: 私有变量只能在其所在类中直接使用,在其它类中不可以直接使用。 8.阅读下列程序,程序中已经指明错误位置,请说出错误原因。 其中,方法m的功能是把形参的值赋给类的成员变量x。 classAlpha{ privateintx; publicvoidm(intx){ x=x;//此处有错误 } } 应该修改为: this.x=x; 9.下面定义了一个完整的类,包括有构造方法。 阅读这段程序,程序中已经指明错误位置,请说出错误原因。 classAlpha{ privateintx; voidAlpha(){//此处有错误 x=0; } publicvoidgetX(){ returnx; } } 错误原因: 构造方法不能有返回类型,也不能以void作为它的返回类型。 10.定义一个名字为MyRectangle的矩形类,类中有4个私有的整型成员变量,分别是矩形的左上角坐标(xUp,yUp)和右下角坐标(xDown,yDown);类中定义了无参数的构造方法和有4个int参数的构造方法,用来初始化类对象。 类中还有以下方法: getW()-计算矩形的宽度; getH()-计算矩形的高度; area()-计算矩形的面积; toString()-把矩形的宽、高和面积等信息作为一个字符串返回。 编写应用程序使用MyRectangle类。 答: publicclassMyRectangle{ privateintxUp,yUp,xDown,yDown; MyRectangle(){ xUp=0;yUp=0;xDown=0;yDown=0; } MyRectangle(x1,y1,x2,y2){ xUp=x1;yUp=y1;xDown=x2;yDown=y2; } publicintgetW(){ returnxDown-xUp; } publicintgetH(){ returnyDown-yUp; } publicintarea(){ returngetW()*getH(); } publicStringtoString(){ return"矩形宽: "+getW()+"矩形高: "+getH()+"矩形面积: "+area();} publicstaticvoidmain(Stringargs[]){ MyRectanglerectangle=newMyRectangle(1,2,7,8); System.out.println(rectangle.toString()); } } 11.定义一个表示学生的类Student,包括的成员变量有: 学号、姓名、性别、年龄;成员方法有: 获得学号、姓名、性别、年龄;修改年龄。 并书写Java程序创建Student类的对象及测试其方法的功能。 答: publicclassStudent{ privateStringnumber,name; privatebooleansex;//true表示“男”,false表示“女” privateintage; Student(){ number="";;sex=true;age=0 } Student(Stringnum,Stringna,booleans,inta){ number=num;sex=s;age=a; } publicStringgetNumber(){ returnnumber; } publicStringgetName(){ returnname; } publicbooleangetSex(){ returnsex; } publicintgetAge(){ returnage; } publicvoidsetAge(inta){ age=a; } publicStringtoString(){ return"学号: "+number+"姓名: "+name+"性别: "+sex+"年龄: "+age; } 篇二: Myfavouritepet(dog) 英语大作战 英语大作战之作文《Myfavouritepet》制作人: 痴人笑看事无常编号: 2021510160213MyfavouritepetIhaveadog.Heismyfavoritepet.Heisverylovely.HisnameisMikeandheisoneyearold.Hisfurislongandwhite.Hehasbigblackeyes.Hisnoseisverygood.Hecansmellverywell.Heisquitesmall.Heweighsabouttwokilograms.Mike’sfavoritefoodismeat.Healsolikesbones. Mikeisveryfriendly.Ifeedhimeveryday.Heneverbarksorbites.Mikelikeslotsofexercise.Itisnecessarytowalkthedogintheparkeverydayifyouwantittobehealthy.SoIplaywithhimeverydayinthepark.Mikelikestoruninthepark.Heoftenchasescatsandbirds.Itisveryinteresting.Mikecanfindthewaybackeasily.Ithinkheisthecleverestanimalofall. Ilikemydogandhelovesmetoo.Heisveryhealthy.Allmyfamilylikehim.Welookafterhimverycarefully.I’llmakeasmallandlovelyhouseforhim.Ithinkhewillbehappytolivethere.Doyoulikemydog? IhavealovelylttledognamedDion.Helooksprettywithshortlegs,bigearsandshorttail.Heismygoodfriendandheisalsoeasytotakecareof.Iwalkhimatleasttwiceaday,feedhimandspendtimewithhim.Healsogiveshislovetomeinreturn.Heisalwaystheretolickmeandlieonme.Ilikeplayingwithhim.IthinkhecantellwhenIamhappy,sad,angryortoubled.Sometimeshecanbenoisyandrunaroundtheroom. Inaword,heisnotonlymydog,butalsomyfriend. Manypeoplelikekeepingananimalasapet.,Ilikesmallanimalsverymuch,soIhavealovelylittledog,hisnameisDion.(IhavealovelylittledognamedDion).Thedogisbrown,hehasfourshortlegs,sohelooksverypretty(漂亮).Hehastwobigearsandashorttail.Heismygoodfriendandheisalsoeasytotakecareof.Heisloyaltomyfamiliesandme,sowealllikehim.IoftentakesawalkwithhimafterIfinishmywork,andIlikeplayingwithhim,feedinghimandspendingtimewithhim.Healsogiveshislovetomeinreturn.Hecanhelpmyfamilylookafterourhouse.IthinkhecantellwhenIamhappy,sad,angryorintouble.Butsometimeshecanbenoisyandrunaroundtheroom.Atnightwhenhemakesmuchnoise,Ican’tsleepwell.Andhelikesholdingthingsinhismouthhereandthere,InthemorningwhenIgetup,Idon’toftenfindmyshoes,Thatmakesmeunhappy. Inaword,heisnotonlymydog,butalsomyfriend. 篇三: It'sbeensolongsinceI'vehadsexI'veforgottenwhotiesupwhom.JoanRivers It'sbeensolongsinceI'vehadsexI'veforgottenwhotiesupwhom.JoanRivers Sleepisanexcellentwayoflisteningtoanopera.JamesStephens.Anyonewhocannotcopewithmathematicsisnotfullyhuman.Atbestheisatolerablesubhumanwhohaslearnedtowearshoes,bathe,andnotmakemessesinthehouse.RobertHeinlein Biologicallyspeaking,ifsomethingbitesyouit'smorelikelytobefemale.DesmondMorris. Humanbeings,whoarealmostuniqueinhavingtheabilitytolearnfromtheexperienceofothers,arealsoremarkablefortheirapparentdisinclinationtodoso.DouglasAdams. Ifyou'resickandtiredofthepoliticsofcynicismandpollsandprinciples,comeandjointhiscampaign.GeorgeWBush Theyfuckyouup,yourmumanddad.Theymaynotmeantobuttheydo.TheyfillupwiththefaultstheyhadAndaddsomeextra,justforyou.PhilipLarkin WhendidIrealizeIwasGod? Well,IwasprayingandIsuddenlyrealizedIwastalkingtomyself.PeterO'Toole. ThelasttimeIwasinSpainIgotthroughsixJeffreyArchernovels.Imustremembertotakeenoughtoiletpapernexttime.BobMonkhouse.Anysufficientlyadvancedbugisindistinguishablefromafeature.BruceBrown Womentakeclothingmuchmoreseriouslythanmen.I'veneverseenamanwalkintoapartyandsayOh,myGod,I'msoembarrassed;getmeoutofhere.There'sanothermanwearingablacktuxedo.RitaRudner TheBritishSecretServicewasstaffedatonepointalmostentirelybyalcoholichomosexualsworkingfortheKGB.CliveJames. Onlyonemaneverunderstoodme,andhedidn'tunderstandme.G.W.Hegel.InmyhouseI'mtheboss.Mywifeisjustthedecisionmaker.WoodyAllenYou'reonlyasgoodasyourlasthaircut.FranLebowitz Alotofpeopleareafraidofheights.Notme,I'mafraidofwidths.StevenWright Idon'tknow.Idon'tcare.Anditdoesn'tmakeanydifference.Television! Teacher,mother,secretlover.HomerSimpson Beforesoftwarecanbereusableitfirsthastobeusable.RalphJohnsonIdon'tthinkanyoneshouldwritetheirautobiographyuntilafterthey'redead.SamuelGoldwyn Codingstylesarelikeassholes,everyonehasoneandnoonelikesanyoneelses.EricWarmenhoven Abankerisafellowwholendsyouhisumbrellawhenthesunisshiningandwantsitbacktheminuteitbeginstorain.MarkTwain Mr.Rightiscoming.Buthe'sinAfricaandhe'swalking.OprahWinfreyHappinessishavingalarge,loving,caring,close-knitfamilyinanothercity.GeorgeBurns He'sthekindofmanawomanwouldhavetomarrytogetridof.MaeWestSubmittedbyVeersoroutThinkingtoomuchcanonlycauseproblemsMailyourpackagesearlysothepostofficecanlosethemintimeforChristmas.JohnnyCarson. Hetaughtmehousekeeping;whenIdivorceIkeepthehouse.ZsaZsaGaborInancienttimestheyhadnostatisticssotheyhadtofallbackonlies.StephenLeacock. ThebestdoctorsintheworldareDoctorDiet,DoctorQuietandDoctorMerryman.JonathanSwift Haveenoughsensetoknow,aheadoftime,whenyourskillswillnotextendtowallpapering.MarilynvosSavant Womenrepresentthetriumphofmatterovermind,justasmenrepresentthetriumphofmindovermorals.OscarWilde Somepeoplethinkfootballisamatteroflifeanddeath.Iassureyou,it'smuchmoreseriousthanthat.BillS
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- MyDogSex
![提示](https://static.bdocx.com/images/bang_tan.gif)