zoukankan      html  css  js  c++  java
  • 项目三(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();
    	}
    }
    

      

  • 相关阅读:
    求1977!
    三进制小数
    回文数C语言
    JAVA知识点必看
    servlet HttpServletRequest
    为什么web工程要输入localhost或者是127.0.0.1
    service $sce or ng-bind-html
    jQuery的deferred对象详解
    理解promise
    理解Angular中的$apply()以及$digest()
  • 原文地址:https://www.cnblogs.com/hxtblogs/p/7649556.html
Copyright © 2011-2022 走看看