欢迎来到天天文库
浏览记录
ID:34254233
大小:62.50 KB
页数:9页
时间:2019-03-04
《java++开发实战经典第六章课后习题答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、interfaceClassName{publicStringgetClassName();}classCompanyimplementsClassName{privateStringclassName;publicCompany(){}publicCompany(StringclassName){this.className=className;}publicStringgetClassName(){returnthis.className;}}publicclassExecDemo01{publ
2、icstaticvoidmain(Stringargs[]){ClassNamecn=newCompany("Company类");System.out.println(cn.getClassName());}}abstractclassShape{publicabstractfloatarea();}classTriangleextendsShape{privatefloatfoot;privatefloatheight;publicTriangle(){}publicTriangle(float
3、foot,floatheight){this.setFoot(foot);this.setHeight(height);}publicfloatarea(){returnthis.foot*height/2;}publicvoidsetFoot(floatfoot){this.foot=foot;}publicvoidsetHeight(floatheight){this.height=height;}publicfloatgetFoot(){returnthis.foot;}publicfloat
4、getHeight(){returnthis.height;}}classCycleextendsShape{privatefloatradius;privatestaticfinalfloatPI=3.1415926f;publicCycle(){}publicCycle(floatradius){this.setRadius(radius);}publicfloatarea(){returnPI*this.radius*this.radius;}publicvoidsetRadius(float
5、radius){this.radius=radius;}publicfloatgetRadius(){returnthis.radius;}}publicclassExecDemo02{publicstaticvoidmain(Stringargs[]){Shapes1=newTriangle(30.0f,50.6f);Shapes2=newCycle(25.3f);System.out.println(s1.area());System.out.println(s2.area());}}abstr
6、actclassPerson{privateStringname;privateStringaddr;privatecharsex;privateintage;publicPerson(){}publicPerson(Stringname,Stringaddr){this(name,addr,'男',0);}publicPerson(Stringname,Stringaddr,charsex,intage){this.setName(name);this.setAddr(addr);this.set
7、Sex(sex);this.setAge(age);}publicabstractStringgetInfo();publicvoidsetName(Stringname){this.name=name;}publicvoidsetAddr(Stringaddr){this.addr=addr;}publicvoidsetSex(charsex){this.sex=sex;}publicvoidsetAge(intage){this.age=age;}publicStringgetName(){re
8、turnthis.name;}publicStringgetAddr(){returnthis.addr;}publicchargetSex(){returnthis.sex;}publicintgetAge(){returnthis.age;}}classStudentextendsPerson{privatefloatmath;privatefloatenglish;publicStudent(){}publicStudent(Stringname,Stringa
此文档下载收益归作者所有