标签:add gets 河北 div 类的设计 logs extend lis highlight
编程实现Person类,学生类的设计及其继承关系
(同第六章课后第三题)
class Person{ private String name; private String addr; private String sex; private int age; public Person(){ System.out.println("声明一个人类"); } public Person(String name,String addr){ this(); this.name=name; this.addr=addr; } public Person(String name,String addr,String sex,int age){ this(name,addr); this.sex=sex; this.age=age; } public String getName(){ return this.name; } public String getAddr(){ return this.addr; } public String getSex(){ return this.sex; } public int getAge(){ return this.age; } public void print(){ System.out.println("人类信息----->姓名:"+this.getName()+"; 地址:"+this.getAddr()+"; 性别:"+this.getSex()+"; 年龄:"+this.getAge()); } } class Student extends Person{ private float math; private float english; public Student(){ super(); System.out.println("此人是个学生"); } public Student(String name,String addr){ super(name,addr); } public Student(String name,String addr,String sex,int age,float math,float english){ super(name,addr,sex,age); this.math=math; this.english=english; } public void print(){ System.out.println("学生信息----->姓名:"+this.getName()+"; 地址:"+this.getAddr()+"; 性别:"+this.getSex()+"; 年龄:"+this.getAge()+"; 数学成绩:"+this.math+"; 英语成绩:"+this.english); } } public class Person01{ public static void main(String args[]){ Person per1=null; Person per2=null; per1=new Person("张三","河北保定","男",30); per2=new Student("张小三","河北保定","男",15,88.0f,77.0f); per1.print(); per2.print(); } }
标签:add gets 河北 div 类的设计 logs extend lis highlight
原文地址:http://www.cnblogs.com/hxtblogs/p/7649556.html