• 项目三(2)——person与学生


     编程实现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();
    	}
    }
    

      

  • 相关阅读:
    堆内存内部结构
    JVM 总体结构
    HTTP的工作原理
    HTTP协议简介
    服务器硬件资源_I/O
    maven常用命令行总结
    java enum—枚举的应用
    JAVA闰年的判断
    JAVA数据结构与算法——求最大公约数!!
    ThinkPHP 分页
  • 原文地址:https://www.cnblogs.com/hxtblogs/p/7649556.html
Copyright © 2020-2023  润新知