码迷,mamicode.com
首页 > 其他好文 > 详细

作业五

时间:2016-04-08 13:14:27      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

class Person{
private String name;
private String addr;
private char sex;
private int age;

public void setName(String name){
this.name = name;
}
public void setAddr(String addr){
this.addr = addr;
}
public void setSex(char sex){
this.sex = sex;
}
public void setAge(int age){
this.age = age;
}

public Person(String name,String addr,char sex,int age){
this.setName(name);
this.setAddr(addr);
this.setSex(sex);
this.setAge(age);
}
public Person(String name,int age){
this.setName(name);
this.setAge(age);
}
public Person(){}

public String getInfo(){
return "name: "+this.name+
"; addr: "+this.addr+
"; sex: "+this.sex+
"; age: "+this.age;
}

public void say(){
System.out.println(this.getInfo());
}
}


class Student extends Person{
private int math;
private int english;

public void setMath(int math){
this.math = math;
}
public void setEnglish(int english){
this.english = english;
}

public Student(String name,String addr,char sex,int age,int math,int english){
super(name,addr,sex,age);
this.math = math;
this.english = english;
}
public Student(String name,int age){
super(name,age);
}
public Student(){};

public String getInfo(){
return super.getInfo()+
"; math: "+this.math+
"; english: "+this.english;
}

public void say(){
super.say();
}
}

public class Test{
public static void main(String[] args){
Person per1 = new Person("小赵",22);
Person stu1 = new Student("小钱","北京",‘M‘,20,80,90);
Student stu2= new Student("小孙","河北",‘M‘,21,85,95);
per1.say();
stu1.say();
stu2.say();
}
}

技术分享

作业五

标签:

原文地址:http://www.cnblogs.com/chendi0912/p/5367614.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!