版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Birdmotianlun/article/details/50202495
函数的复写(override)又称覆盖。重写
//super可以调用父类方法
class person{
String name;
int age;
void shuchu(){
System.out.pringln(name+age);
}
}
class student extends person{
String address;
//复写父类方法
void shuchu(){
super.shuchu(); //System.out.pringln(name+age);//
System.out.pringln(address);
}
}
class test{
public static void main(String args[]){
student s=new student();
s.name="zhangsan";
s.age=20;
s.address="beijing";
a.shuchu();
}
}