重写
一:重写是父类与子类之间多态的一种表现。
二:重写方法的参数列表必须与被重写的方法完全相同。
三:重写方法的访问符一定要大于被重写方法的访问修饰符,要保证public>protected>default>private.
四:下面是重写方法的一些代码
public class Person {
String name;
int age;
char sex;
public void show() {
System.out.println("姓名:"+name+"年龄"+age+"性别:"+sex);
}
public class Student extends Person{
int i;
String yuanxi;
public void show() {
System.out.println("姓名:"+name+"年龄"+age+"性别:"+sex+"学号"+i+"院系"+yuanxi);
}
}
public class StudentExample {
public void main(String args[]) {
Student a=new Student();
a.name="莫";
a.age=20;
a.sex='男';
a.i=20203049;
a.yuanxi="大数据";
a.show();
}
}