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