当前位置:   article > 正文

建立一个Person类和学生类_创建一个person类

创建一个person类

    class Person{
	String name;
	String addr;
	char sex;
	int age;
	public Person(String name,String addr,char sex,int age){
		System.out.println("姓名:"+name+"  地址:"+addr+"  性别:"+sex+"  年龄:"+age);
		this.name=name;
		this.addr=addr;
		this.sex=sex;
		this.age=age;
	}
	public Person(String name,char sex){
		System.out.println("姓名:"+name+"  性别:"+sex);
		this.name=name;
		this.sex=sex;
	}
	public Person(){
	}
	public void getinfo(){
		System.out.println("姓名:"+name+"  地址:"+addr+"  性别:"+sex+"  年龄:"+age);
	}
}
class Student extends Person{
	float math;
	float english;
	public Student(String name,String addr,char sex,int age,float math,float english){
		super(name,addr,sex,age);
		this.math=math;
		this.english=english;
	}
	public Student(String name,char sex){
		System.out.println("姓名:"+name+"  性别:"+sex);
	}
	public Student(){
		
	}
	public void getinfo(){
		System.out.println("姓名:"+name+"  地址:"+addr+"  性别:"+sex+"  年龄:"+age+"  数学成绩:"+math+"  英语成绩:"+english);
	}
}
public class t63 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Person p=new Person("里西斯","上海",'男',34);
		Student s1=new Student("赵晓赵",'女');
		Student s2=new Student("赵小赵","河北",'女',18,100,100);
		Student s3=new Student("赵小小赵","云南",'女',17,100,100);
		Student s4=new Student("赵晓小小赵","北京",'女',16,100,100);
		Student s5=new Student("赵小小小赵","桂林",'女',13,100,100);
		
	}

}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/136464
推荐阅读
  

闽ICP备14008679号