Java实验报告
Java 实验报告实验报告 学号:
1413032033 姓名:黄珊珊 班级:软件工程 142
实验一 题目一:
编写程序,要求创建一个抽象类 Father,其中有身高,体重等属性及爱好(唱歌)等方法,创建子类 Son 类继承 Father 类,并增加性格这个属性,改写父类的方法(爱好)。
源代码:
Public class test{ Public static void main(String args[]){ Son son=new Son(“儿子”,1.75f,66f,”足球”);son.showInfo();Son.singsong();} } Abstract class Father{ Float high,weight;Protected String name;Father(String name,float high,float weight){ this.name=name;this.high=high;this.weight=weight;} Abstract void singsong();Abstract void showInfo();} Class Son extend Father { String hobby;Son(String name,float high,float weight,String hobby){ Super(name,high,weight);This.hobby=hobby;} Void singsong(){ System.out.Println(name+”is singing loudly!”);} void showInfo(){ System.out.Println(“姓名:”name+”;身高:”+high+”;体重:”+weight+”;爱好:”+hobby);运行截图:
实验小结
