1. Person-Student 继承演示
// Person.java
package com.yx.demo3;
public class Person {
String name;
char sex;
int age;
public Person(){
}
public Person(String name, char sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
}
public String toString(){
return name + " " + sex + " " + age;
}
}
package com.yx.demo3;
public class Student extends Person {
long number;
int math;
int english;
int computer;
public Student(String name,char sex,int age,long number,int math,int english,int computer){
//方法一 ,直接给调用继承得到的属性赋值
this.name = name;
this.sex = sex;
this.age = age; // name,sex,age 都是父类person 继承过来的
//方法二 ,调用父类的构造方法去赋值,super关键字 ,
//这里的父类person有构造函数的重载,可以调用 super(name,age,sex);
// super(name,sex,age);
this.numb