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

作业六

时间:2016-04-07 18:21:17      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

3(1)

class Person3{
private String name;
private String addr;
private String sex;
private int age;
public Person3(String name,String addr,String sex,int age){
this.name=name;
this.addr=addr;
this.sex=sex;
this.age=age;
}
public Person3(String name,int age){
this.name=name;
this.age=age;
}
public Person3(){

}
public String getName(){
return name;
}
public void setName(String n){
name=n;
}
public String getAddr(){
return addr;
}
public void setAddr(String ad){
addr=ad;
}
public String getSex(){
return sex;
}
public void setSex(String s){
sex=s;
}
public int getAge(){
return age;
}
public void setAge(int a){
age=a;
}
}
public class Person {
public static void main(String args[]) {
Person3 per=null;
per=new Person3("XX","北京市顺义区牛栏山镇北京工业大学耿丹学院","男",20);
System.out.println("姓名:"+per.getName());
System.out.println("地址:"+per.getAddr());
System.out.println("性别:"+per.getSex());
System.out.println("年龄:"+per.getAge());
System.out.println("\t");
per=new Person3("XX",20);
System.out.println("姓名:"+per.getName());
System.out.println("地址:"+per.getAddr());
System.out.println("性别:"+per.getSex());
System.out.println("年龄:"+per.getAge());
System.out.println("\t");
per=new Person3();
System.out.println("姓名:"+per.getName());
System.out.println("地址:"+per.getAddr());
System.out.println("性别:"+per.getSex());
System.out.println("年龄:"+per.getAge());
}
}

技术分享技术分享技术分享

3(2)

class Person4{
private String name;
private String addr;
private String sex;
private int age;
public Person4(String name,String addr,String sex,int age){
this.name=name;
this.addr=addr;
this.sex=sex;
this.age=age;
}
public Person4(String name,int age){
this.name=name;
this.age=age;
}
public Person4(){

}
public String getName(){
return name;
}
public void setName(String n){
name=n;
}
public String getAddr(){
return addr;
}
public void setAddr(String ad){
addr=ad;
}
public String getSex(){
return sex;
}
public void setSex(String s){
sex=s;
}
public int getAge(){
return age;
}
public void setAge(int a){
age=a;
}
}
class Chidren2 extends Person4{
private float math;
private float english;
public Chidren2(){
}
public float getMath(){
return math;
}
public void setMath(float math){
this.math=math;
}
public float getEnglish(){
return english;
}
public void setEnglish(float english){
this.english=english;
}
}
public class ExtDemo {
public static void main(String args[]) {
Chidren2 stu=new Chidren2();
stu.setName("XXX");
stu.setAddr("北京市顺义区牛栏山镇北京工业大学耿丹学院");
stu.setSex("男");
stu.setAge(20);
stu.setMath(80.5f);
stu.setEnglish(90.5f);
System.out.println("姓名:"+stu.getName());
System.out.println("地址:"+stu.getAddr());
System.out.println("性别:"+stu.getSex());
System.out.println("年龄:"+stu.getAge());
System.out.println("数学成绩:"+stu.getMath());
System.out.println("英语成绩:"+stu.getEnglish());
System.out.println("\t");
stu=new Chidren2();
stu.setName("XXX");
stu.setAge(20);
System.out.println("姓名:"+stu.getName());
System.out.println("地址:"+stu.getAddr());
System.out.println("性别:"+stu.getSex());
System.out.println("年龄:"+stu.getAge());
System.out.println("数学成绩:"+stu.getMath());
System.out.println("英语成绩:"+stu.getEnglish());
System.out.println("\t");
stu=new Chidren2();
System.out.println("姓名:"+stu.getName());
System.out.println("地址:"+stu.getAddr());
System.out.println("性别:"+stu.getSex());
System.out.println("年龄:"+stu.getAge());
System.out.println("数学成绩:"+stu.getMath());
System.out.println("英语成绩:"+stu.getEnglish());
}

}

技术分享技术分享技术分享

作业六

标签:

原文地址:http://www.cnblogs.com/chasingli/p/5364674.html

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